| Stefan [MSFT] 2004-09-08, 5:49 pm |
| Hi Cat,
no wonder!
You are using from the CmsHttpContext and not from the
CmsApplicationContext.
Mean the ch object is taken from the CmsHttpContext and not from the
CmsApplicationContent
And the CmsHttpContext is most likely not in update mode.
Please retrieve all object from the AppContext and not from the cmsContext
and your code will work:
Dim cmsContext As CmsHttpContext = CmsHttpContext.Current
Dim AppContext As CmsApplicationContext = New CmsApplicationContext
AppContext. AuthenticateAsCurrentUser(PublishingMode
.Update)
If cmsContext.Channel.Name = "Vacancies" Then
AppContext.SessionSettings.AutoFilterHidden = False
Dim ch As Channel =
AppContext.Searches.GetByGuid(cmsContext.Channel.Guid) as Channel;
Dim pCol As PostingCollection
pCol = ch.Postings
Dim p, pMove As Posting
For Each p In pCol
Dim pDisplayName As String = p.DisplayName & p.UrlModeUpdate
If p.State = PostingState.Expired Then
Dim chDestination As Channel = AppContext.Searches.GetByPath("URL")
If (AppContext.Mode = PublishingMode.Update And p.CanMove) Then
p.MoveTo(chDestination)
If Err.Number = 0 Then
Call AppContext.CommitAll()
End If
End If
End If
Next
AppContext.SessionSettings.AutoFilterHidden = True
End If
Cheers,
Stefan.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
MCMS FAQ:
http://download.microsoft.com/downl...6a/MCMS+2002+-+(complete)+FAQ.htm
MCMS Blog: http://blogs.msdn.com/stefan_gossner/category/4983.aspx
MCMS Sample Code:
http://www.gotdotnet.com/community/...t+S
erver
MCMS Whitepapers and other docs:
http://blogs.msdn.com/stefan_gossne...2/07/41859.aspx
--------------------------------
"Cat" <catriona.morrison@ced.glasgow.gov.uk> wrote in message
news:d75afc34.0409080529.20d96ba5@posting.google.com...
> I am trying to move expired postings using moveto. I've tried
> everything I can and nothing seems to work. I could copyto but when I
> tried to delete the posting I got the same error.
>
> "Invalid mode for update. The requested action modifies the state of
> an object and can only be performed when the session is in the
> 'Update' mode."
>
> Here's my code:
>
> Dim cmsContext As CmsHttpContext = CmsHttpContext.Current
> Dim AppContext As CmsApplicationContext = New CmsApplicationContext
> AppContext. AuthenticateAsCurrentUser(PublishingMode
.Update)
>
> If cmsContext.Channel.Name = "Vacancies" Then
> cmsContext.SessionSettings.AutoFilterHidden = False
> Dim ch As Channel = cmsContext.Channel
> Dim pCol As PostingCollection
> pCol = ch.Postings
> Dim p, pMove As Posting
> For Each p In pCol
> Dim pDisplayName As String = p.DisplayName & p.UrlModeUpdate
> If p.State = PostingState.Expired Then
> Dim chDestination As Channel = cmsContext.Searches.GetByPath("URL")
> If (AppContext.Mode = PublishingMode.Update And p.CanMove) Then
> p.MoveTo(chDestination)
> If Err.Number = 0 Then
> Call cmsContext.CommitAll()
> End If
> End If
> End If
> Next
> cmsContext.SessionSettings.AutoFilterHidden = True
> End If
>
> Any Ideas?
>
> Cheers
> Cat
|