Developer forum

Forum » CMS - Standard features » Delete item and page?

Delete item and page?

Martin Christensen
Reply

Hi,

I need to delete some item based pages from frontend. Can I do this without messing up the database? I figure there may be relations that will fail if not done properly.

I'm basically doing this in my template:

Dynamicweb.Content.Items.Item.GetItemById(string itemtype,itemid).Delete();

I found that deleting just the item like this leaves behind the page to which it was previously attached. Opening the page then results in an error, since the PAGEITEMID now points to a deleted reference.

I can also grab the pageid related to that item and do this:

Dynamicweb.Services.Pages.DeletePage(pageid);

Will this be sufficient or am I messing up the database?

 

Best regards

Martin Christensen


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Martin

GetItemById(string itemtype,itemid).Delete(); is very low level, so not very suitable for what you are doing. It removes the item record from database as the only thing.

Dynamicweb.Services.Pages.DeletePage(pageid); is much more comprehensive. It takes care of item on the page, property item, paragraphs and their items, subpages and also moves all of it to the recycly bin instead of a hard delete and ensure that your cache is up to date.

So in short, Dynamicweb.Services.Pages.DeletePage(pageid) is the right option.

Votes for this answer: 1
 
Martin Christensen
Reply

Hi Nicolai

Great, its even simpler than I thought.

Thanks for the quick reply!

 

You must be logged in to post in the forum