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

Syntax

public Node CurrentNode { get; }

Property Value

Type: Node

Remarks

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.

Examples

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.StartBookmark("MyBookmark");
builder.Writeln("Bookmark contents.");
builder.EndBookmark("MyBookmark");

// 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
builder.MoveToBookmark("MyBookmark");

// 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);
Assert.IsTrue(builder.IsAtStartOfParagraph);

// A shorter way of moving the very start/end of a document is with these methods
builder.MoveToDocumentEnd();

Assert.IsTrue(builder.IsAtEndOfParagraph);

builder.MoveToDocumentStart();

Assert.IsTrue(builder.IsAtStartOfParagraph);

See Also