FieldIsDirty Property

Gets or sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.

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


public bool IsDirty { get; set; }

Property Value

Type: Boolean


Shows how to use special property for updating field result.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Give the document's built in property "Author" a value and display it with a field
doc.BuiltInDocumentProperties.Author = "John Doe";
FieldAuthor field = (FieldAuthor)builder.InsertField(FieldType.FieldAuthor, true);

Assert.AreEqual("John Doe", field.Result);

// Update the "Author" property
doc.BuiltInDocumentProperties.Author = "John & Jane Doe";

// AUTHOR is one of the field types whose fields do not update according to their source values in real time,
// and need to be updated manually beforehand every time an accurate value is required
Assert.AreEqual("John Doe", field.Result);

// Since the field's value is out of date, we can mark it as "Dirty"
field.IsDirty = true;

using (MemoryStream docStream = new MemoryStream())
    doc.Save(docStream, SaveFormat.Docx);

    // Re-open the document from the stream while using a LoadOptions object to specify
    // whether to update all fields marked as "Dirty" in the process, so they can display accurate values immediately
    LoadOptions options = new LoadOptions();
    options.UpdateDirtyFields = doUpdateDirtyFields;
    doc = new Document(docStream, options);

    Assert.AreEqual("John & Jane Doe", doc.BuiltInDocumentProperties.Author);

    field = (FieldAuthor)doc.Range.Fields[0];

    if (doUpdateDirtyFields)
        Assert.AreEqual("John & Jane Doe", field.Result);
        Assert.AreEqual("John Doe", field.Result);

See Also