Last active
September 29, 2021 18:59
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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