Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
What is this page about?
This page explains how to navigate a document using the document cursor and associated API operations.
While working with a document, even if it is a short or long one, you will need to navigate through your document. Navigation with a virtual cursor represents the ability to navigate between different nodes in a document.
Within a short document, moving around in a document is simple as you can move the insertion point even by using the keyboard’s arrow keys or by clicking the mouse to locate the insertion point wherever you want. But once you have a large document that has many pages, these basic techniques will be insufficient.
This article explains how to move around in a document and navigate with a virtual cursor to different parts of it.
Before starting the process of navigating through your document, you will need to get the node that is currently selected. You can get the exact position of the cursor at a selected node by using the CurrentNode property. In addition, instead of getting the current node, you can get the currently selected paragraph or the currently selected section by using the CurrentParagraph and CurrentSection properties.
Any insert operations you perform using the DocumentBuilder will be inserted before the CurrentNode. When the current paragraph is empty or the cursor is positioned just before the end of the paragraph, the CurrentNode returns null.
When you are editing text, it is important to know how to navigate your document and where exactly to move in it. Aspose.Words allows you to move around in a document and navigate to its different sections and parts – this is similar to the functionality of the Navigation Pane in Microsoft Word to go to a page or heading in a Word document without scrolling.
The main method is to be able to move the cursor position to a specific node in your document, you can achieve this by using the MoveTo method.
The following code example shows how to move the DocumentBuilder to different nodes in a document:
But besides the basic MoveTo method, there are more specific ones.
You can go to the beginning or the end of your document using the MoveToDocumentStart and MoveToDocumentEnd methods.
The following code example shows how to move the cursor position to the beginning or the end of a document:
You can mark a place that you want to find and move to it again easily. You can insert as many bookmarks into your document as you want, and then navigate through them by identifying the bookmarks with unique names. You can move to a bookmark by using the MoveToBookmark method.
The following code examples shows how to move a cursor position to a bookmark:
You can move to a table cell by using the MoveToCell method. This method will enable you to navigate your cursor into any cell in a specific table. In addition, you can specify an index to move the cursor to any position or specified character in a cell within the MoveToCell method.
The following code example shows how to move a cursor position to a specified table cell:
You can move to a specific field in your document by using the MoveToField method. In addition, you can move to a specific merge field by using the MoveToMergeField method.
The following code example shows how to move the document builder cursor to a specific field:
You can move to the beginning of a header or footer by using the MoveToHeaderFooter method.
The following code example shows how to move document builder cursor to a document header or footer:
You can move to a specific section or paragraph by using the MoveToParagraph or MoveToSection methods. In addition, you can specify an index to move the cursor to any position or a specified character in a paragraph within the MoveToParagraph method.
The following code example shows how to move to a specific section and a specific paragraph in a document:
Q: How can I obtain the node where the cursor is currently positioned?
A: Use the DocumentBuilder.CurrentNode property. It returns the node that the builder is positioned before. If the cursor is at the start of an empty paragraph, the property returns null. You can also retrieve the current paragraph or section via CurrentParagraph and CurrentSection.
Q: How do I move the cursor to a specific bookmark?
A: Call DocumentBuilder.MoveToBookmark("BookmarkName"). Ensure the bookmark exists; you can create one with DocumentBuilder.StartBookmark("BookmarkName") and DocumentBuilder.EndBookmark("BookmarkName").
Q: How can I navigate to the header or footer of a particular section?
A: Use DocumentBuilder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary) or HeaderFooterType.FooterPrimary. If you need to target a specific section, set DocumentBuilder.CurrentSection first or pass the section index to the method overload.
Q: How do I move the cursor to a cell inside a table?
A: Use DocumentBuilder.MoveToCell(table, rowIndex, columnIndex). Optionally, provide a character offset within the cell to place the cursor at a precise position.
Q: How can I move the cursor to the beginning or the end of the document?
A: Call DocumentBuilder.MoveToDocumentStart() to place the cursor at the very start, or DocumentBuilder.MoveToDocumentEnd() to place it at the end of the document.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.