FieldBuilderBuildAndInsert(Inline) Method

Builds and inserts a field into the document before the specified inline node.

Namespace:  Aspose.Words.Fields
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.10.0

ExpandedSyntax

public Field BuildAndInsert(
	Inline refNode
)

Parameters

refNode
Type: Aspose.WordsInline

Return Value

Type: Field
A Field object that represents the inserted field.

ExpandedExamples

Builds and inserts a field into the document before the specified inline node.
Document doc = new Document();

// A convenient way of adding text content to a document is with a DocumentBuilder
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write(" Hello world! This text is one Run, which is an inline node.");

// Fields can be constructed in a similar way with a FieldBuilder, with arguments and switches added individually
// In this case we will construct a BARCODE field which represents a US postal code
FieldBuilder fieldBuilder = new FieldBuilder(FieldType.FieldBarcode);
fieldBuilder.AddArgument("90210");
fieldBuilder.AddSwitch("\\f", "A");
fieldBuilder.AddSwitch("\\u");

// Insert the field before any inline node
fieldBuilder.BuildAndInsert(doc.FirstSection.Body.FirstParagraph.Runs[0]);
doc.UpdateFields();
doc.Save(ArtifactsDir + "Field.CreateWithFieldBuilder.docx");

ExpandedSee Also