Ordering of Comments

I’ve noticed that when adding multiple comments to various places in a paragraph, the comments often end up out-of-order. Specifically, if I first add a comment on the last word of a paragraph (using CommentRangeStart and CommentRangeEnd), and then add a comment to the first word of the paragraph, the comment on the last word will appear in Word as comment “1”, and the second will be comment “2”, even though the second is earlier in the text. Additionally, the first comment will sometimes (but not always) be positioned before the second comment in the margin of the Word document.
In the code that I am porting from Interop, comments are added all over a paragraph, and not necessarily in order (that is, a comment on the last word will often be added before a comment on the first word); yet, Word Interop always ends up ordering the comments correctly, so that they line up in the margin (and in their numbering) according to the order of where they occur in the paragraph, and not according to when they were added.
Is there any way to have Aspose similarly order the comments according to the CommentRangeStart, rather than according to when they were added?

Hi Avi,

Thanks for your query. Aspose.Words mimics the same behavior as MS Word do. I have tested the scenario with following code snippet and have not found any issue with comments ordering while using latest version of Aspose.Word for .NET. Please use the latest version of Aspose.Words for .NET.

Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// E.g this is the Paragraph to which comments will added
Paragraph paragraph = doc.FirstSection.Body.LastParagraph;
// Create a Comment.
Comment comment = new Comment(doc);
// Insert some text into the comment.
Paragraph commentParagraph = new Paragraph(doc);
commentParagraph.AppendChild(new Run(doc, "This is last comment!!!"));
comment.AppendChild(commentParagraph);
// Move to paragraph where comments will be added
builder.MoveTo(paragraph);
// Insert comment
builder.InsertNode(comment);
// E.g this is the Paragraph to which comments will added
paragraph = doc.FirstSection.Body.FirstParagraph;
// Create a Comment.
Comment comment2 = new Comment(doc);
// Insert some text into the comment.
Paragraph commentParagraph2 = new Paragraph(doc);
commentParagraph2.AppendChild(new Run(doc, "This is first comment!!!"));
comment2.AppendChild(commentParagraph2);
// Move to paragraph where comments will be added
builder.MoveTo(paragraph);
// Insert comment
builder.InsertNode(comment2);
doc.Save(MyDir + "AsposeOut.docx");

Please let us know if you have any more queries.

Please note, my query was not with regard to comments in different paragraphs, but rather to multiple comments placed within the same paragraph, anchored on different words in the paragraph (via CommentRangeStart and CommentRangeEnd).
Here, I find that with Word interop, I can first place a comment on the last word of the paragraph, and then on the first word of the paragraph, and the comments will be ordered appropriately. However, with Aspose.Words, the comment on the last word maintains the earlier number.

Hi Avi,

Thanks for sharing the details. Aspose.Words mimics the same behavior as MS Word do. If you add the comments in the same Paragraph by using MS Words, you will get the same behavior. It would be great if you please share your input document along with code for investigation purposes.

Please also share your desired output document.