DocumentBuilderMoveToParagraph Method

Moves the cursor to a paragraph in the current section.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0


public void MoveToParagraph(
	int paragraphIndex,
	int characterIndex


Type: SystemInt32
The index of the paragraph to move to.
Type: SystemInt32
The index of the character inside the paragraph. Currently can only specify 0 to move to the beginning of the paragraph or -1 to move to the end of the paragraph.


The navigation is performed inside the current story of the current section. That is, if you moved the cursor to the primary header of the first section, then paragraphIndex specified the index of the paragraph inside that header of that section.

When paragraphIndex is greater than or equal to 0, it specifies an index from the beginning of the section with 0 being the first paragraph. When paragraphIndex is less than 0, it specified an index from the end of the section with -1 being the last paragraph.


Shows how to move a cursor position to the specified paragraph.
// Open a document with a lot of paragraphs
Document doc = new Document(MyDir + "Paragraphs.docx");
ParagraphCollection paragraphs = doc.FirstSection.Body.Paragraphs;

Assert.AreEqual(22, paragraphs.Count);

// When we create a DocumentBuilder for a document, its cursor is at the very beginning of the document by default,
// and any content added by the DocumentBuilder will just be prepended to the document
DocumentBuilder builder = new DocumentBuilder(doc);

Assert.AreEqual(0, paragraphs.IndexOf(builder.CurrentParagraph));

// We can manually move the DocumentBuilder to any paragraph in the document via a 0-based index like this
builder.MoveToParagraph(2, 0);
builder.Writeln("This is a new third paragraph. ");

See Also