| Mei Ying [MVP] 2005-01-31, 8:50 pm |
| Hi
Looks like the same problem as mentioned in the post.
Getting a CmsApplicationContext object in update mode is
not sufficient to update objects. You will need to use it
to get all objects that need updating as well. In this
case, that would be the "channel" object.
Something like this:
---
//get a context in update mode
CmsApplicationContext updateContext = new
CmsApplicationContext();
WindowsIdentity ident = HttpContext.Current.User.Identity
as WindowsIdentity;
updateContext.AuthenticateUsingUserHandle
(ident.Token,PublishingMode.Update);
//get the channel in update mode
Channel myChannel = updateContext.Searches.GetByPath
("/Channels/myChannel/") as Channel;
//approve all postings in myChannel in update mode
foreach(Posting myPosting in myChannel.Postings)
{
while(myPosting.CanApprove)
{
myPosting.Approve();
updateContext.CommitAll();
}
}
//IMPT: dispose the update context
updateContext.Dispose();
---
So _cmsHelper.MainSiteChannelSearch should return a
channel that was retrieved in the update mode. If you can,
post the code of the the MainSiteChannelSearch method here
and we can take a look at it.
regards
Mei Ying
---
Blog: http://meiyinglim.blogspot.com
Book: http://www.packtpub.com/book/mcms
Contact: meiyinglim@hotmail.com
---
>-----Original Message-----
>I want to add an "approve all" button to the default
console. I'm
>having trouble writing the code that would do this.
Below is the code
>that I have so far. I'm getting casting problems when
trying to use
>the solution give here:
>http://groups-
beta.google.com/group/microsoft.public.cmserver.general/bro
wse_frm/thread/d595d1cf03cbc5d9/51e2dd9e069f14ba#51e2dd9e06
9f14ba
>lmk what you guys suggest?
>
>thanx,
>Innis
>
>private void btnApproveAll_Click(object sender,
System.EventArgs e)
>{
>
>ApproveAllPostings();
>}
>
>// Get the CMS application context
>CmsApplicationContext context = new CmsApplicationContext
();
>
>
>private void ApproveAllPostings()
>
>
>{
>// Get the CMS application context
>CmsApplicationContext context = new CmsApplicationContext
();
>WindowsIdentity ident =
>(WindowsIdentity)HttpContext.Current.User.Identity;
>
>CMSHelper _cmsHelper = new CMSHelper();
>Channel channel = _cmsHelper.MainSiteChannelSearch
>(CmsHttpContext.Current.Channel);
>
>
>// // Make sure to set the context to be in
the Update mode,
>context.AuthenticateUsingUserHandle
(ident.Token,PublishingMode.Update);
>
>
>this.RecursiveApprove(channel);
>
>
>
>}
>
>
>public void RecursiveApprove(Channel channel)
>
>{
>foreach(Posting posting in channel.Postings)
>{
>this.Response.Write (posting.DisplayName);
>
>posting.Approve();
>
>
>context.CommitAll();
>}
>
>
>foreach(Channel subChannel in channel.Channels)
>{
> this.RecursiveApprove
(subChannel);
> }
>
> }
>
>.
>
|