DocumentNormalizeFieldTypes Method

Changes field type values FieldType of FieldStart, FieldSeparator, FieldEnd in the whole document so that they correspond to the field types contained in the field codes.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0


public void NormalizeFieldTypes()


Use this method after document changes that affect field types.

To change field type values in a specific part of the document use NormalizeFieldTypes.


Shows how to get the keep a field's type up to date with its field code.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a date field
Field field = builder.InsertField("DATE", null);

// Based on the field code we entered above, the type of the field has been set to "FieldDate"
Assert.AreEqual(FieldType.FieldDate, field.Type);

// We can manually access the content of the field we added and change it
Run fieldText = (Run)doc.FirstSection.Body.FirstParagraph.GetChildNodes(NodeType.Run, true)[0];
fieldText.Text = "PAGE";

// We changed the text to "PAGE" but the field's type property did not update accordingly
Assert.AreEqual("PAGE", fieldText.GetText());
Assert.AreEqual(FieldType.FieldDate, field.Type);

// After running this method the type of the field, as well as its FieldStart,
// FieldSeparator and FieldEnd nodes to "FieldPage", which matches the text "PAGE"

Assert.AreEqual(FieldType.FieldPage, field.Type);

See Also