.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

FieldCollection.Update() Method

Updates all fields in the collection.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v21.2.Core.dll

Declaration

void Update()

Remarks

Use the Field.Update method to update a field. The Document.UpdateAllFields method allows you to update all fields in the document.

Examples

The examples below demonstrate how to update all fields in specific parts of a document (main body, text box, header, footer, comment, footnote, and endnote).

Update Fields in the Main Document Body

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
//...

using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
    // Access a document.
    Document document = wordProcessor.Document;
    //...
    // Update all fields in the main document body.
    document.Fields.Update();
}

Update Fields in Text Boxes

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
//...

using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
    // Access a document.
    Document document = wordProcessor.Document;
    // Check all shapes in the document.
    foreach (Shape shape in document.Shapes)
    {
        // Check whether the shape is a text box.
        if (shape.ShapeFormat.HasText)
        {
            // Access text box content.
            SubDocument textBoxDocument = shape.ShapeFormat.TextBox.Document;
            //...
            // Update all fields in the text box.
            textBoxDocument.Fields.Update();
        }
    }
}

Update Fields in Headers and Footers

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
//...

using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
    // Access a document.
    Document document = wordProcessor.Document;
    // Check all document sections.
    foreach (Section section in document.Sections)
    {
        // Check whether the section has a primary header.
        if (section.HasHeader(HeaderFooterType.Primary))
        {
            // Start to edit the document header.
            SubDocument headerContent = section.BeginUpdateHeader();
            //...
            // Update all fields in the document header.
            headerContent.Fields.Update();
            // Finalize to edit the document header.
            section.EndUpdateHeader(headerContent);
        }

        // Check whether the section has a primary footer.
        if (section.HasFooter(HeaderFooterType.Primary))
        {
            // Start to edit the document footer.
            SubDocument footerContent = section.BeginUpdateFooter();
            //...
            // Update all fields in the document footer.
            footerContent.Fields.Update();
            // Finalize to edit the document footer.
            section.EndUpdateFooter(footerContent);
        }
    }
}

Update Fields in Comments

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
//...

using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
    // Access a document.
    Document document = wordProcessor.Document;
    // Check all document comments.
    foreach (Comment comment in document.Comments)
    {
        // Access comment content.
        SubDocument commentContent = comment.BeginUpdate();
        //...
        // Update all fields in the comment.
        commentContent.Fields.Update();
        // Finalize to edit the comment.
        comment.EndUpdate(commentContent);
    }
}

Update Fields in Footnotes and Endnotes

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
//...

using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
    // Access a document.
    Document document = wordProcessor.Document;
    // Check all document footnotes.
    foreach (Note footnote in document.Footnotes)
    {
        // Access footnote content.
        SubDocument footnoteContent = footnote.BeginUpdate();
        //...
        // Update all fields in the footnote.
        footnoteContent.Fields.Update();
        // Finalize to edit the footnote.
        footnote.EndUpdate(footnoteContent);
    }

    // Check all document endnotes.
    foreach (Note endnote in document.Endnotes)
    {
        // Access endnote content.
        SubDocument endnoteContent = endnote.BeginUpdate();
        //...
        // Update all fields in the endnote.
        endnoteContent.Fields.Update();
        // Finalize to edit the endnote.
        endnote.EndUpdate(endnoteContent);
    }
}
See Also