DocumentBuilderMoveToField Method

Moves the cursor to a field in the document.

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


public void MoveToField(
	Field field,
	bool isAfter


Type: Aspose.Words.FieldsField
The field to move the cursor to.
Type: SystemBoolean
When true, moves the cursor to be after the field end. When false, moves the cursor to be before the field start.


Shows how to move document builder's cursor to a specific field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a field using the DocumentBuilder and add a run of text after it
Field field = builder.InsertField("MERGEFIELD field");
builder.Write(" Text after the field.");

// The builder's cursor is currently at end of the document

// We can move the builder to a field like this, placing the cursor at immediately after the field
builder.MoveToField(field, true);

// Note that the cursor is at a place past the FieldEnd node of the field, meaning that we are not actually inside the field
// If we wish to move the DocumentBuilder to inside a field,
// we will need to move it to a field's FieldStart or FieldSeparator node using the DocumentBuilder.MoveTo() method
Assert.AreEqual(field.End, builder.CurrentNode.PreviousSibling);

builder.Write(" Text immediately after the field.");

See Also