Free Support Forum - aspose.com

ParagraphIndex

Is this the best way to get the current paragraphIndex?

var paraIndex = builder.CurrentSection.ChildNodes.Cast<Node>().Count(node => node.NodeType == NodeType.Paragraph);

I need the index in order to go back to the beginning of the specified paragraph later using the MoveToParagraph function.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I think, it is better to use code like the following:

NodeCollection paragraphs = builder.CurrentSection.GetChildNodes(NodeType.Paragraph, true);

int paraIndex = paragraphs.IndexOf(par);

Also, you can move DocumentBuilder cursor to the specified paragraph using MoveTo method. You should just pass a paragraph as a parameter.

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/aspose.words.documentbuilder.moveto.html

Hope this helps.

Best regards.