DocumentBuilderMoveToMergeField Method (String, Boolean, Boolean)
Moves the merge field to the specified merge field.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.10
public bool MoveToMergeField(
	string fieldName,
	bool isAfter,
	bool isDeleteField


Type: SystemString
The case-insensitive name of the mail merge field.
Type: SystemBoolean
When true, moves the cursor to be after the field end. When false, moves the cursor to be before the field start.
Type: SystemBoolean
When true, deletes the merge field.

Return Value

Type: Boolean
True if the merge field was found and the cursor was moved; false otherwise.
Shows how to insert merge fields and move between them.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertField(@"MERGEFIELD MyMergeField1 \* MERGEFORMAT");
builder.InsertField(@"MERGEFIELD MyMergeField2 \* MERGEFORMAT");

Assert.AreEqual(2, doc.Range.Fields.Count);

// The second merge field starts immediately after the end of the first
// We'll move the builder's cursor to the end of the first so we can split them by text
builder.MoveToMergeField("MyMergeField1", true, false);

builder.Write(" Text between our two merge fields. ");

doc.Save(ArtifactsDir + "DocumentBuilder.MergeFields.docx");
See Also