Sitefinity CMS allows you to delete a comment through the Comments API.
When deleting a news comment, you must perform the following:
Get the news item.
First, get an instance of the master version of the news item that corresponds to the specified ID.
For more information about finding specific news items, see For developers: Query news items.
Get the live version.
The instance that corresponds to the ID argument is the master version of the news item. You can get the live version explicitly.
Get the comment.
Get the comment that corresponds to the specified ID.
Delete the comment.
After you get the comment, you delete it.
Save the changes.
Finally, you save all changes.
The following examples delete a news comment by its ID.
DeleteCommentByIdNativeAPI(Guid masterNewsId, Guid commentId)
NewsManager newsManager = NewsManager.GetManager();
// Check whether the news item exists
NewsItem news = newsManager.GetNewsItems().Where(nI => nI.Id == masterNewsId).FirstOrDefault();
news = newsManager.Lifecycle.GetLive(news)
// Get the comment
Comment comment = newsManager.GetComments().Where(c => c.CommentedItemID == news.Id && c.Id == commentId).SingleOrDefault();
// Delete the comment
// Save the changes
First, you get an instance of the NewsManager class. You get the specified news item by querying all items and filtering the collection by the ID property.
If the item exists, you get its live version. Then, you get the comment by calling GetComments and filtering based on theCommentedItemID and Id properties. Then, you delete the comment by calling the Delete method of the manager. Finally, you save the changes.
DeleteCommentByIdFluentAPI(Guid masterNewsId, Guid commentId)
newsCount = 0;
App.WorkWith().NewsItems().Where(nI => nI.Id == masterNewsId).Count(
(newsCount > 0)
var liveNewsItem = App.WorkWith().NewsItem(masterNewsId).GetLive();
commentCount = 0;
// Check whether the comment exists
liveNewsItem.Comments().Where(c => c.Id == commentId).Count(
(commentCount > 0)
Then, you use the GetLive method of the singular facade to get the instance of the live version. You initialize the plural facade of the comments by calling Comments. Then, you get the comment by filtering based on the Id property. You delete the comment by calling theDelete method of the singular facade of the comment. Finally, you save the changes.
Back To Top