RangeUpdateFields Method

Updates the values of document fields in this range.

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


public void UpdateFields()


When you open, modify and then save a document, Aspose.Words does not update fields automatically, it keeps them intact. Therefore, you would usually want to call this method before saving if you have modified the document programmatically and want to make sure the proper (calculated) field values appear in the saved document.

There is no need to update fields after executing a mail merge because mail merge is a kind of field update and automatically updates all fields in the document.

This method does not update all field types. For the detailed list of supported field types, see the Programmers Guide.

This method does not update fields that are related to the page layout algorithms (e.g. PAGE, PAGES, PAGEREF). The page layout-related fields are updated when you render a document or call UpdatePageLayout.

To update fields in the whole document use UpdateFields.


Shows how to update document fields in the body of the first section only.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a field that will display the value in the document's body text
FieldDocProperty field = (FieldDocProperty)builder.InsertField(" DOCPROPERTY Category");

// Set the value of the property that should be displayed by the field
doc.BuiltInDocumentProperties.Category = "MyCategory";

// Some field types need to be explicitly updated before they can display their expected values
Assert.AreEqual(string.Empty, field.Result);

// Update all the fields in the first section of the document, which includes the field we just inserted

Assert.AreEqual("MyCategory", field.Result);

ExpandedSee Also