Microsoft Content Management Server - Microsoft.ContentManagement.Publishing.CmsInvalidModeException: In

This is Interesting: Free IT Magazines  
Home > Archive > Microsoft Content Management Server > December 2005 > Microsoft.ContentManagement.Publishing.CmsInvalidModeException: In





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Microsoft.ContentManagement.Publishing.CmsInvalidModeException: In
JJ

2005-12-23, 7:49 am

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!

Stefan [MSFT]

2005-12-23, 7:49 am

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!
>



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com