Delete comments

Sitefinity CMS allows you to delete a single comment or a group of comments through the Comments API.

Delete a single comment by its key

When deleting a comment, you must perform the following:

  1. Get an instance of the comments service by using the SystemManager's GetCommentsService method.
  2. Delete the comment using the DeleteComment method of the comments service. The method expects the comment key as a parameter.

Consider the code sample below:


Delete multiple comments by their keys

When deleting multiple comments, follow the steps below:

  1. Get an instance of the comments service using the SystemManager's GetCommentsService method.
  2. Delete all comments using the DeleteComments method of the comments service. The methods expects a collection of comment keys as a parameter.

Consider the code sample below:



Delete all comments for a specific content type

In case you  need to delete programmatically all comments for a specific content type, for example News, follow the steps below:

  1. Get an instance of the comments service.
    Use the GetCommentsService method of the SystemManager.
  2. To find all comments related to News, you use the CommentFilter and add NewsItem full type name as a criteria.
    Thus, you can use the GetComments method and pass the filter as an argument. For more information, see Query comments.
  3. Delete comments.
    After retrieving all keys of the comments, you can use the DeleteComments method. 

Consider the code sample below:



Delete all comments for a specific content item by the item's ID

You may need to programmatically delete all comments for a specific content item by the item's ID. In the following example, you delete all comments for a specific News item by its ID. Follow the steps below:

  1. Get an instance of the comments service.
    Use the GetCommentsService method of the SystemManager.
  2. To find all comments related to the specific News item, you use the ID of the News item and create a new thread key.
    Add the thread key in the CommentFilter and use the filter the get all comments. For more information, see Query comments.

Consider the code sample below:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?

Next article

Work with threads