How do I add multiple comments (using loop) on specific location

Hi @awais.hafeez,
How do I add multiple comments (using loop) on specific location using above code.
thank you!.

@cpai.sachin Please see our documentation to learn how to work with comments:
https://docs.aspose.com/words/net/working-with-comments/
Please let us know if you need additional information.

Hi @alexey.noskov thank you.
Appreciate your quick response let me go through the given link.
Will come back to you in case of any concern.

1 Like

Hi @alexey.noskov, my concern is that,
My first call is extracting the comment from given document and save that comment to my database.
Second call is fetch existing comments from database and add to current document on specific location against metadata saved while extracting.
thank you!

@cpai.sachin You can store the comments in a temporary document in your data base to preserve their metadata and cotent. then you can use code like this to extract comments and insert them into the destination document at a specific location:

Document doc = new Document(@"C:\Temp\src.docx");

// Get all comments form the source document.
List<Comment> comments = doc.GetChildNodes(NodeType.Comment, true).Cast<Comment>().ToList();

// To store comments in your data base you can use a document as a container for comments.
Document commentsContainer = new Document();
foreach (Comment comment in comments)
{
    Node importedComment = commentsContainer.ImportNode(comment, true);
    commentsContainer.FirstSection.Body.FirstParagraph.AppendChild(importedComment);
}
// Save the comments container into the database. For demo purposes to file.
commentsContainer.Save(@"C:\Temp\tmp_container.docx");

// ...............
// Later once comments are extracted from DB, you can insert them into the destination document
// at the specific location, for example at bookmark.

Document dst = new Document(@"C:\Temp\dst.docx");
Bookmark dstBookmakr = dst.Range.Bookmarks["specific_location"];
foreach (Comment comment in comments)
{
    Node importedComment = dst.ImportNode(comment, true);
    dstBookmakr.BookmarkEnd.ParentNode.InsertBefore(importedComment, dstBookmakr.BookmarkEnd);
}

dst.Save(@"C:\temp\out.docx");
1 Like

Thanks @alexey.noskov.

1 Like