In this topic, we will learn how to delete comments from Word document in C#. The comment annotation is usually added to suggest improvements or changes while reviewing the DOCX or DOC format document. The code snippet and the steps will help you understand the simple process to remove comment section from Word in C#.
Steps to Delete Comments from Word Document in C#
- Install Aspose.Words library with NuGet package manager
- Load the input Word document using the Document Class object
- Get all the comments in the document using the NodeType.Comment enumerator
- Delete the comments using the Clear() method in the NodeCollection
- Save the output file in the desired format
These steps summarize how to remove comments on Microsoft Word in C#. Simply load the input document and access all of its comments from the nodes collection using the NodeType.Comment enumerator. Subsequently, remove all the comments and save the updated file to the disk or stream.
Code to Delete Comments from Word Document in C#
This code sample demonstrates the basic scenario of how to delete comment in Microsoft Word in C#. Whereas, you can enhance it to delete selective comments based on author names, comment date, comment text, etc. based on your requirements. So you can improvise the code snippet to meet your application needs with only a few API calls.
This tutorial has guided us about the process to remove comments on Word document in C#. However, if you want to learn the reverse process of inserting comments, refer to the article on how to insert comment into Word document using C#.