Skip to content

Instantly share code, notes, and snippets.

How to Insert Comment into Word Document using C#. More details and steps can be found here https://kb.aspose.com/words/net/how-to-insert-comment-into-word-document-using-c-sharp/
using Aspose.Words;
using System;
namespace InsertCommentinWord
{
class how_to_insert_comment_into_word_document_using_c_sharp
{
public static void InsertComment(String directorypath)
{
//Set Aspose license before importing document.
Aspose.Words.License AsposeWordsLicense = new Aspose.Words.License();
AsposeWordsLicense.SetLicense(directorypath + @"Aspose.Words.lic");
//Import the Document into Aspose.Words DOM.
Document doc = new Document(directorypath + "input.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
//Move the cursor to the beginning of the document.
builder.MoveToDocumentStart();
//Insert comment to first paragraph of document.
Comment comment = new Comment(doc, "Aspose.Words", "AW", DateTime.Today);
builder.CurrentParagraph.AppendChild(comment);
comment.Paragraphs.Add(new Paragraph(doc));
comment.FirstParagraph.Runs.Add(new Run(doc, "Comment text."));
//Save the Document
doc.Save(directorypath + @"output.docx", SaveFormat.Docx);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment