Microsoft.ContentManagement.Publishing.CmsInvalidModeException: In
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Microsoft Content Management Server > Microsoft.ContentManagement.Publishing.CmsInvalidModeException: In




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Microsoft.ContentManagement.Publishing.CmsInvalidModeException: In  
JJ


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-23-05 12:49 PM

Hi,

I got an invalid mode exception when I try to write some resources into the
resourcegallery. I got the code which uses Web services to load a whole
directory of resources into the gallery. It work well. I put the similar cod
e
into the CMS project but it gives me the error. I debug through the project
and found it to be in update mode. Why is the system still giving me the
exception?

CmsApplicationContext cmsContext = new CmsApplicationContext();
// Logon to MCMS:
// Assumes that you have Windows Authentication turned on.
WindowsIdentity ident = HttpContext.Current.User.Identity as WindowsIdentity
;

// Make sure to set the context to Update mode (which means you can write
// back to MCMS using PAPI).

cmsContext.AuthenticateUsingUserHandle(ident.Token,PublishingMode.Update);
if (cmsContext.Mode == PublishingMode.Update)
{
foreach(FileSystemInfo fsi in dir.GetFileSystemInfos())
{
FileInfo f = (FileInfo)fsi;
rsg.CreateResource(f.FullName);
i++;
}
}

Please help.

Thanks!






[ Post a follow-up to this message ]



    Re: Microsoft.ContentManagement.Publishing.CmsInvalidModeException: In  
Stefan [MSFT]


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-23-05 12:49 PM

Hi JJ,

you did not retrieve the rsg object using the new context.
The context is bound to the objects.
So if you retrieved rsg using a different context which is not in update
mode this will happen.

You could easily solve this using the following code change:

CmsApplicationContext cmsContext = new CmsApplicationContext();
// Logon to MCMS:
// Assumes that you have Windows Authentication turned on.
WindowsIdentity ident = HttpContext.Current.User.Identity as
WindowsIdentity;

// Make sure to set the context to Update mode (which means you can write
// back to MCMS using PAPI).

cmsContext.AuthenticateUsingUserHandle(ident.Token,PublishingMode.Update);
ResourceGallery rsg_update = cmsContext.Searches.GetByGuid(rsg.Guid) as
ResourceGallery;
if (cmsContext.Mode == PublishingMode.Update)
{
foreach(FileSystemInfo fsi in dir.GetFileSystemInfos())
{
FileInfo f = (FileInfo)fsi;
rsg_update.CreateResource(f.FullName);
cmsContext.CommitAll();
i++;
}
}

Cheers,
Stefan

--
This posting is provided "AS IS" with no warranties, and confers no rights

New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
Check out the new book as well: Advanced MCMS development:
http://tinyurl.com/8ugwj
----------------------


"JJ" <JJ@discussions.microsoft.com> wrote in message
news:AD3B4A9D-EB1F-4983-A3CB-604BAE8E645F@microsoft.com...
> Hi,
>
> I got an invalid mode exception when I try to write some resources into
> the
> resourcegallery. I got the code which uses Web services to load a whole
> directory of resources into the gallery. It work well. I put the similar
> code
> into the CMS project but it gives me the error. I debug through the
> project
> and found it to be in update mode. Why is the system still giving me the
> exception?
>
> CmsApplicationContext cmsContext = new CmsApplicationContext();
> // Logon to MCMS:
> // Assumes that you have Windows Authentication turned on.
> WindowsIdentity ident = HttpContext.Current.User.Identity as
> WindowsIdentity;
>
> // Make sure to set the context to Update mode (which means you can write
> // back to MCMS using PAPI).
>
> cmsContext.AuthenticateUsingUserHandle(ident.Token,PublishingMode.Update);
> if (cmsContext.Mode == PublishingMode.Update)
> {
>   foreach(FileSystemInfo fsi in dir.GetFileSystemInfos())
>  {
> FileInfo f = (FileInfo)fsi;
> rsg.CreateResource(f.FullName);
> i++;
>  }
> }
>
> Please help.
>
> Thanks!
>







[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 02:50 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register