ParagraphAppendField Method (String, String)

Appends a field to this paragraph.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public Field AppendField(
	string fieldCode,
	string fieldValue
)

Parameters

fieldCode
Type: SystemString
The field code to append (without curly braces).
fieldValue
Type: SystemString
The field value to append. Pass null for fields that do not have a value.

Return Value

Type: Field
A Field object that represents the appended field.
Examples
Shows how to insert fields in different ways.
// Create a blank document and get its first paragraph
Document doc = new Document();
Paragraph para = doc.FirstSection.Body.FirstParagraph;

// Choose a field by FieldType, append it to the end of the paragraph and update it
para.AppendField(FieldType.FieldDate, true);

// Append a field with a field code created by hand 
para.AppendField(" TIME  \\@ \"HH:mm:ss\" ");

// Append a field that will display a placeholder value until it is updated manually in Microsoft Word
// or programmatically with Document.UpdateFields() or Field.Update()
para.AppendField(" QUOTE \"Real value\"", "Placeholder value");

// We can choose a node in the paragraph and insert a field
// before or after that node instead of appending it to the end of a paragraph
para = doc.FirstSection.Body.AppendParagraph("");
Run run = new Run(doc) { Text = " My Run. " };
para.AppendChild(run);

// Insert a field into the paragraph and place it before the run we created
doc.BuiltInDocumentProperties["Author"].Value = "John Doe";
para.InsertField(FieldType.FieldAuthor, true, run, false);

// Insert another field designated by field code before the run
para.InsertField(" QUOTE \"Real value\" ", run, false);

// Insert another field with a place holder value and place it after the run
para.InsertField(" QUOTE \"Real value\"", " Placeholder value. ", run, true);

doc.Save(ArtifactsDir + "Paragraph.InsertField.docx");
See Also