Sitefinity CMS

Deleting Content Items Send comments on this topic.
See Also
Developing with Sitefinity > Modules > Modules API > Generic Content > Content Items > Deleting Content Items

Glossary Item Box

Content Items can be deleted in two ways:

  • DeleteContent(IContent content) - Delete an item which is passed as parameter
  • DeleteContent(Guid contentID) - Delete an item with an ID passed as parameter
By deleting the content item, all comments belonging to this item will be deleted as well.

 Delete a content item which is passed as parameter:

DeleteContent(IContent content) Copy Code
// create new instance of ContentManager
Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager();
// get all content items
IList listOfContentItems = contentManager.GetContent();
if (listOfContentItems.Count > 0)
{
   
// get the third content item
   
Telerik.Cms.Engine.IContent thirdContent = contentManager.GetContent(((Telerik.Cms.Engine.IContent)listOfContentItems[2]).ID);
   Response.Write(thirdContent.GetMetaData(
"Name") + "<br />");
   
// delete the content item
   
contentManager.DeleteContent(thirdContent);
}

 

Delete a content item with an ID passed as parameter:

DeleteContent(Guid contentID) Copy Code
// create new instance of ContentManager
Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager();
// get all content items
IList listOfContentItems = contentManager.GetContent();
if (listOfContentItems.Count > 0)
{
   
// get the second content item
   
Telerik.Cms.Engine.IContent secondContent = contentManager.GetContent(((Telerik.Cms.Engine.IContent)listOfContentItems[1]).ID);
   Response.Write(secondContent.GetMetaData(
"Name") + "<br />");
   
// delete the content item
   
contentManager.DeleteContent(secondContent.ID);
}

 

 

See Also