A comment is a note or a type of annotation which is usually added to a document when a user wants to add remarks, notes, reminder, or a feedback to it. For instance, when multiple users work on the same document, it becomes easy for them to leave a note, remarks or feedback for each other’s reference.
In DsWord, comments are represented by the Comment class. It allows you to modify the content and other properties of the comments, such as, author, date of the comment, etc. DsWord allows you to add or insert comments in a Word document using Add or Insert method of the CommentCollection class respectively. In addition, it lets you add and delete the comment replies as well. You can use Reply method of the Comment class to add a new comment as a reply into the comments collection and the Delete method to delete it.
To add comments in a document:
C# |
Copy Code |
---|---|
doc.Load("CommentInWord.docx"); //Access the first paragraph Paragraph par = doc.Body.Sections.First.GetRange().Paragraphs[0]; //Add comment Comment c=par.GetRange().Comments.Add("CommentByCode","GC"); //Save the document doc.Save("AddComment.docx"); |
To modify a comment through code:
C# |
Copy Code |
---|---|
doc.Load("AddComment.docx"); //Access the first paragraph Paragraph par = doc.Body.Sections.First.GetRange().Paragraphs[0]; //Modify the first comment's author and initials par.GetRange().Comments[0].Author = "DsWordUser"; par.GetRange().Comments[0].Initials = "D.S.W"; //Mark the comment reply as closed par.GetRange().Comments[0].Done = true; doc.Save("ModifiedComment.docx"); |
To delete a comment:
C# |
Copy Code |
---|---|
doc.Load("CommentInWord.docx"); //Delete the second comment doc.Body.Comments[3].Delete(); doc.Save("DeleteComment.docx"); |
To add a reply on a comment:
C# |
Copy Code |
---|---|
doc.Load("CommentInWord.docx"); //Add comment reply for the last comment in the document doc.Body.Comments.Last.Reply("Reply Comment", "John Doe"); //Add a comment reply Comment cReply = c.Reply("Reply of the added comment", "JD"); //Mark the comment reply as closed cReply.Done = true; //Save the document doc.Save("AddComment.docx"); |
To delete a reply on the comment:
C# |
Copy Code |
---|---|
//Delete first comment's first reply doc.Body.Comments.First.Replies[0].Delete(); doc.Save("DelComment.docx"); |
For more information on how implement comments using DsWord, see DsWord sample browser.