FieldGetFieldCode Method (Boolean)

Returns text between field start and field separator (or field end if there is no separator).

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

Syntax

public string GetFieldCode(
	bool includeChildFieldCodes
)

Parameters

includeChildFieldCodes
Type: SystemBoolean
True if child field codes should be included.

Return Value

Type: String

Examples

Shows how to get text between field start and field separator (or field end if there is no separator).
// Open a document which contains a MERGEFIELD inside an IF field
Document doc = new Document(MyDir + "Nested fields.docx");

// Get the outer IF field and print its full field code
FieldIf fieldIf = (FieldIf)doc.Range.Fields[0];
Console.WriteLine($"Full field code including child fields:\n\t{fieldIf.GetFieldCode()}");

// All inner nested fields are printed by default
Assert.AreEqual(fieldIf.GetFieldCode(), fieldIf.GetFieldCode(true));

// Print the field code again but this time without the inner MERGEFIELD
Console.WriteLine($"Field code with nested fields omitted:\n\t{fieldIf.GetFieldCode(false)}");

See Also