Get comment's paragraph and section number

Hi

I am able to extract all the comments from document, but I also need the comment’s paragraph and section index it is attached to. I know comment can be attached to multiple paragraph, so maybe an index of comment Range Start index would work.

Here is what I am trying to do in vb .net, but I know it is wrong:

Dim p As Paragraph
Dim pindex As String
Dim s As Section
Dim sindex As String

Dim collectedComments As New ArrayList()
’ Collect all comments in the document
Dim comments As NodeCollection = doc.GetChildNodes(NodeType.Comment, True)
’ Look through all comments and gather information about them.
For Each comment As Comment In comments


p = comment.GetAncestor(NodeType.Paragraph)
pindex = doc.GetChildNodes(NodeType.Paragraph, True).IndexOf§.ToString()

s = p.GetAncestor(NodeType.Section)
sindex = doc.GetChildNodes(NodeType.Section, True).IndexOf(s).ToString()


collectedComments.Add(comment.Author & " " & comment.DateTime & " " & comment.ToString(SaveFormat.Text) & " " & pindex & " " & sindex)

Next comment

I tried changing the code a little to see if I can move the cursor using builder and get correct paragraph. But that did not work. I am not able to get the paragraph index


builder.MoveTo(comment.ParentNode)
Dim p As Paragraph = builder.CurrentParagraph
Dim pindex As String=doc.GetChildNodes(NodeType.Paragraph, True).IndexOf§.ToString()

Hi Cary,

Thanks for your inquiry. We suggest you please use Comment.ParentParagraph property to get the parent paragraph of comment node. Regarding getting the paragraph index, please use Body.Paragraphs.IndexOf method. Hope this helps you. The Document.GetChildNodes method returns the collection of child nodes from whole document (including document's header and footers).

If you still face problem, please share your input document and expected results here for testing purposes. We will investigate the issue on our side and provide you more information.