Microsoft Content Management Server - CmsPosting_Deleting

This is Interesting: Free IT Magazines  
Home > Archive > Microsoft Content Management Server > October 2004 > CmsPosting_Deleting





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 CmsPosting_Deleting
bill tie

2004-10-08, 7:48 am


This is driving me up the wall.

Suppose the channel structure is as follows:

\Channel A
postings A
\Channel B
postings B
\Channel C
postings C

If a user deletes a posting C, I want the program to climb up deleting
postings C, Channel C, postings B, and Channel B.

What will be left is

\Channel A
postings A

Try as I might, the best I could do is delete everything I wanted (I checked
in the Site Manager}, but the program would crash on an error.

I've tried to do this in CmsPosting_Deleting or CmsPosting_Deleted or both.
I'm at the end of my wits.

Could someone write a quick and dirty (preferably clean) sample code that
would accomplish the exercise?

Thank you.

bill tie

2004-10-08, 5:48 pm


Stefan,

This is a modified and stripped-down version:


public void CmsPosting_Deleted( Object sender, ChangedEventArgs e )
{
CmsContext cmsContext = e.Context;
Posting pPageToDelete = e.Target as Posting;
Channel cChannelToDelete;

if ( pPageToDelete != null )
{
cChannelToDelete = pPageToDelete.Parent;
}

if ( cChannelToDelete.Postings.Count > 0 )
{
foreach ( Posting pPage in cChannelToDelete.Postings )
{
if ( pPage.Name.ToString() == pPageToDelete.Name.ToString() )
{
cmsContext.CommitAll();
}
else
{
pPage.Delete();
}
}
}
else
{
if ( chnChannelToDelete != null )
{
chnChannelToDelete.Delete();
cmsContext.CommitAll();
}
}
} // end

If you have a structure

\Channel A
postings A
\Channel B
postings B

the program is meant to delete

\Channel B
postings B

It does. At least, I don't see the sub-tree in the Site Manager.

But I get a rude error message:

"Object has been deleted. An attempt was made to access the properties or
methods of an object that was deleted by the current session."

I'm open to any suggestions/solutions. If web author console code is
available, I'll take it.

Thank you.

Stefan [MSFT]

2004-10-08, 5:48 pm

Ah!
Ok, the problem is that you need to redirect to a valid URL after the
deletion.
The URL you will get redirected to is the parent channel - which just has
been deleted.
Adding a manualy response.redirect (e.g. to the root channel) should resolve
this.

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


"bill tie" <billtie@discussions.microsoft.com> wrote in message
news:108C9FC1-7C8A-412B-BD0A-39D4BF0D2120@microsoft.com...
>
> Stefan,
>
> This is a modified and stripped-down version:
>
>
> public void CmsPosting_Deleted( Object sender, ChangedEventArgs e )
> {
> CmsContext cmsContext = e.Context;
> Posting pPageToDelete = e.Target as Posting;
> Channel cChannelToDelete;
>
> if ( pPageToDelete != null )
> {
> cChannelToDelete = pPageToDelete.Parent;
> }
>
> if ( cChannelToDelete.Postings.Count > 0 )
> {
> foreach ( Posting pPage in cChannelToDelete.Postings )
> {
> if ( pPage.Name.ToString() == pPageToDelete.Name.ToString() )
> {
> cmsContext.CommitAll();
> }
> else
> {
> pPage.Delete();
> }
> }
> }
> else
> {
> if ( chnChannelToDelete != null )
> {
> chnChannelToDelete.Delete();
> cmsContext.CommitAll();
> }
> }
> } // end
>
> If you have a structure
>
> \Channel A
> postings A
> \Channel B
> postings B
>
> the program is meant to delete
>
> \Channel B
> postings B
>
> It does. At least, I don't see the sub-tree in the Site Manager.
>
> But I get a rude error message:
>
> "Object has been deleted. An attempt was made to access the properties or
> methods of an object that was deleted by the current session."
>
> I'm open to any suggestions/solutions. If web author console code is
> available, I'll take it.
>
> Thank you.
>



bill tie

2004-10-08, 5:48 pm


Angus,

Congratulations on your freshly acquired MVP-ship.

> Why do you want to remove the channel and parent channel if
> a posting is deleted?


Call me meticulous if you will. In hindsight, I didn't have to code this
feature for it may never ever be used on the website we're developing. Yet,
this is the rationale.

If a user deletes the "last" posting in a channel, there is still an index
page (MVPs call it a channel-rendering page).

If the channel is not re-used for a long time, the index page should display
text different from usual. We didn't think it was nice. It seemed easier
just to delete the index page.

If the index page is gone, why have the channel? So let's delete the channel.

However, the parent channel of the deleted channel has a special page in it.
The special page depends on the child channel.

Well, let's delete the special page. If we delete the special page, why
have an empty channel?

Thank goodness, there are no more channels and pages to delete. This note
would get into an endless loop.

bill tie

2004-10-08, 5:48 pm


Response.Redirect. I think I'll remember it till the end of my days.

Thank you, Stefan.
Stefan [MSFT]

2004-10-08, 5:48 pm

Actually you might end of the on the /Channels object left.
This cannot be deleted. Thanks god! ;-)

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


"bill tie" <billtie@discussions.microsoft.com> wrote in message
news:79295A34-B46F-4F5B-9BF8-BF5921EE6A11@microsoft.com...
>
> Angus,
>
> Congratulations on your freshly acquired MVP-ship.
>
>
> Call me meticulous if you will. In hindsight, I didn't have to code this
> feature for it may never ever be used on the website we're developing.

Yet,
> this is the rationale.
>
> If a user deletes the "last" posting in a channel, there is still an index
> page (MVPs call it a channel-rendering page).
>
> If the channel is not re-used for a long time, the index page should

display
> text different from usual. We didn't think it was nice. It seemed easier
> just to delete the index page.
>
> If the index page is gone, why have the channel? So let's delete the

channel.
>
> However, the parent channel of the deleted channel has a special page in

it.
> The special page depends on the child channel.
>
> Well, let's delete the special page. If we delete the special page, why
> have an empty channel?
>
> Thank goodness, there are no more channels and pages to delete. This note
> would get into an endless loop.
>



AC

2004-10-15, 9:13 pm

You ~could~ just create your channel listing page to check and see if there
are postings within a channel before displaying it... so it will no longer
be there.

-AC

"bill tie" <billtie@discussions.microsoft.com> wrote in message
news:79295A34-B46F-4F5B-9BF8-BF5921EE6A11@microsoft.com...
>
> Angus,
>
> Congratulations on your freshly acquired MVP-ship.
>
>
> Call me meticulous if you will. In hindsight, I didn't have to code this
> feature for it may never ever be used on the website we're developing.
> Yet,
> this is the rationale.
>
> If a user deletes the "last" posting in a channel, there is still an index
> page (MVPs call it a channel-rendering page).
>
> If the channel is not re-used for a long time, the index page should
> display
> text different from usual. We didn't think it was nice. It seemed easier
> just to delete the index page.
>
> If the index page is gone, why have the channel? So let's delete the
> channel.
>
> However, the parent channel of the deleted channel has a special page in
> it.
> The special page depends on the child channel.
>
> Well, let's delete the special page. If we delete the special page, why
> have an empty channel?
>
> Thank goodness, there are no more channels and pages to delete. This note
> would get into an endless loop.
>



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com