CommentAncestor Property
Returns the parent Comment object. Returns null for top-level comments.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.10
Syntax
public Comment Ancestor { get; }

Property Value

Type: Comment
Examples
Shows how to get all comments with all replies.
[C#]

Document doc = new Document(MyDir + "Comment.Document.docx");

// Get all comment from the document
NodeCollection comments = doc.GetChildNodes(NodeType.Comment, true);


// For all comments and replies we identify comment level and info about it
foreach (Comment comment in comments.OfType<Comment>())
{
    if (comment.Ancestor == null)
    {
        Console.WriteLine("This is a top-level comment\n");

        Console.WriteLine("Comment author: " + comment.Author);
        Console.WriteLine("Comment text: " + comment.GetText());

        foreach (Comment commentReply in comment.Replies.OfType<Comment>())
        {
            Console.WriteLine("This is a comment reply\n");

            Console.WriteLine("Comment author: " + commentReply.Author);
            Console.WriteLine("Comment text: " + commentReply.GetText());
        }
    }
}
See Also