Insert Word Comment in C#, VB.NET

Word comment, inserted by users to show opinions or additional information about words, phrases or paragraphs, is often appeared in the document margins. According to comments, readers can learn some more information about contents or modify contents to express own thoughts more correctly or clearly.

Spire.Doc for .NET, a professional .NET Word component to manipulate Word documents, enables users to insert comment in Word with C#, VB.NET. Users can invoke paragraph.AppendComment(string) method to insert comment for specified paragraph directly. Also, Spire.Doc for .NET provides a Comment class with users. Users can use Format property offered this class to set format comment.

The following demonstrates how perfect a comment can be. You can also freely download Spire.Doc and have a trial.

Insert Word Comment

//Load Document
            Document document = new Document();
            document.LoadFromFile(@"E:\work\Documents\WordDocuments\Humor Them.docx");

            //Get Paragraph to Insert Comment
            Section section = document.Sections[0];
            Paragraph paragraph = section.Paragraphs[2];

            //Insert Comment
            string str = "This paragraph presents the first example to Humor Them.";
            Comment comment= paragraph.AppendComment(str);
            comment.Format.Author = "E-iceblue";
            comment.Format.Initial = "CM";

            //Save Document


 'Load Document
            Dim document As New Document()
            document.LoadFromFile("E:\work\Documents\WordDocuments\Humor Them.docx")

            'Get Paragraph to Insert Comment
            Dim section As Section = document.Sections(0)
            Dim paragraph As Paragraph = section.Paragraphs(2)

            'Insert Comment
            Dim str As String = "This paragraph presents the first example to Humor Them."
            Dim comment As Comment = paragraph.AppendComment(str)
            comment.Format.Author = "E-iceblue"
            comment.Format.Initial = "CM"

            'Save Document
            document.SaveToFile("comments.docx", FileFormat.Docx2010)

Spire.Doc is a Microsoft Word component, which enables users to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document in WPF, .NET and Silverlight.