FieldBuilder Constructor

Initializes an instance of the FieldBuilder class.

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

ExpandedSyntax

public FieldBuilder(
	FieldType fieldType
)

Parameters

fieldType
Type: Aspose.Words.FieldsFieldType
The type of the field to build.

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