In this topic, we will explain how to insert comment into word document using C#. The comment annotation in MS Word is anchored to a position in text or a region of text. In Aspose.Words’ document object model the comment is an inline-level node and can only be a child of Paragraph. We will use sample input Word document and insert a comment at the start of DOCX with few lines of C# code. You can use the same approach to insert the comment to any paragraph in document.
Steps to Insert Comment into Word Document using C#
- Install Aspose.Words for .NET package from NuGet.org
- Add reference to Aspose.Words
- Set license using License.SetLicense method before importing Document
- Import the input Word document
- Initialize instance of DocumentBuilder class and move the cursor to the beginning of the document
- Initialize instance of the Comment class and add comment’s text using Paragraph
- Add comment to first paragraph of document
- Finally, save the document to Word DOCX file format
Previously, we looked into How to Convert PDF to Word in C# Without Interop. Now, you will learn how to insert comment into DOCX file format.
Code to Insert Comment into Word Document using C#
Inserting comment into Word document using above C# code does not need to install MS Office and can be used where .NET is installed. This code example inserts the comment at the end of first paragraph of document.