DocumentBuilderCurrentNode Property

Gets the node that is currently selected in this DocumentBuilder.

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


public Node CurrentNode { get; }

Property Value

Type: Node


CurrentNode is a cursor of DocumentBuilder and points to a Node that is a direct child of a Paragraph. Any insert operations you perform using DocumentBuilder will insert before the CurrentNode.

When the current paragraph is empty or the cursor is positioned just before the end of the paragraph, CurrentNode returns null.


Shows how to move a DocumentBuilder to different nodes in a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Start a bookmark and add content to it using a DocumentBuilder
builder.Writeln("Bookmark contents.");

// The node that the DocumentBuilder is currently at is past the boundaries of the bookmark  
Assert.AreEqual(doc.Range.Bookmarks[0].BookmarkEnd, builder.CurrentParagraph.FirstChild);

// If we wish to revise the content of our bookmark with the DocumentBuilder, we can move back to it like this

// Now we're located between the bookmark's BookmarkStart and BookmarkEnd nodes, so any text the builder adds will be within it
Assert.AreEqual(doc.Range.Bookmarks[0].BookmarkStart, builder.CurrentParagraph.FirstChild);

// We can move the builder to an individual node,
// which in this case will be the first node of the first paragraph, like this
builder.MoveTo(doc.FirstSection.Body.FirstParagraph.GetChildNodes(NodeType.Any, false)[0]);

Assert.AreEqual(NodeType.BookmarkStart, builder.CurrentNode.NodeType);

// A shorter way of moving the very start/end of a document is with these methods




See Also