FieldGetFieldCode(Boolean) Method

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: 21.1.0


public string GetFieldCode(
	bool includeChildFieldCodes


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

Return Value

Type: String


Shows how to get a field's field code.
// Open a document which contains a MERGEFIELD inside an IF field.
Document doc = new Document(MyDir + "Nested fields.docx");
FieldIf fieldIf = (FieldIf)doc.Range.Fields[0];

// There are two ways of getting a field's field code:
// 1 -  Omit its inner fields:
Assert.AreEqual(" IF  > 0 \" (surplus of ) \" \"\" ", fieldIf.GetFieldCode(false));

// 2 -  Include its inner fields:
Assert.AreEqual($" IF \u0013 MERGEFIELD NetIncome \u0014\u0015 > 0 \" (surplus of \u0013 MERGEFIELD  NetIncome \\f $ \u0014\u0015) \" \"\" ",

// By default, the GetFieldCode method displays inner fields.
Assert.AreEqual(fieldIf.GetFieldCode(), fieldIf.GetFieldCode(true));

ExpandedSee Also