Sitefinity CMS

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

Glossary Item Box

There are two methods for deleting a comment:

  • DeleteComment(IComment comment) - Pass the comment that will be deleted 
  • DeleteComment(Guid ID) - Pass the ID of the comment that will be deleted 

Delete a specified comment:

DeleteComment(IComment comment) 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);
   
// get all comments for the content item thirdContent
   
IList listOfComments = contentManager.GetComments(thirdContent.ID);
   
// get the first comment
   
Telerik.Cms.Engine.IComment firstComment = contentManager.GetComment(((Telerik.Cms.Engine.IComment)listOfComments[0]).ID);
   
// delete the comment in the database
   
contentManager.DeleteComment(firstComment);
}  

 

Delete a comment by its ID:

DeleteComment(Guid ID) 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);
   
// get all comments for the content item thirdContent
   
IList listOfComments = contentManager.GetComments(thirdContent.ID);
   
// get the first comment
   
Telerik.Cms.Engine.IComment firstComment = contentManager.GetComment(((Telerik.Cms.Engine.IComment)listOfComments[0]).ID);
   
// delete the comment in the database
   
contentManager.DeleteComment(firstComment.ID);
}

 

See Also