Skip to main content
All docs
V23.2

FieldCollection.Unlink() Method

Replaces all fields in the collection with field values.

Namespace: DevExpress.XtraRichEdit.API.Native

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

NuGet Packages: DevExpress.RichEdit.Core, DevExpress.Win.Navigation

Declaration

Remarks

The Unlink method converts field results to text or graphics. Unlinked fields cannot be updated.

Use the Field.Unlink method to unlink a field. The Document.UnlinkAllFields method allows you to unlink all fields in the document.

Examples

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

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

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

The following example unlinks all 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;
            //...
            // Unlink all fields in the text box.
            textBoxDocument.Fields.Unlink();
        }
    }
}
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();
            //...
            // Unlink all fields in the document header.
            headerContent.Fields.Unlink();
            // 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();
            //...
            // Unlink all fields in the document footer.
            footerContent.Fields.Unlink();
            // Finalize to edit the document footer.
            section.EndUpdateFooter(footerContent);
        }
    }
}
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();
        //...
        // Unlink all fields in the comment.
        commentContent.Fields.Unlink();
        // Finalize to edit the comment.
        comment.EndUpdate(commentContent);
    }
}
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();
        //...
        // Unlink all fields in the footnote.
        footnoteContent.Fields.Unlink();
        // 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();
        //...
        // Unlink all fields in the endnote.
        endnoteContent.Fields.Unlink();
        // Finalize to edit the endnote.
        endnote.EndUpdate(endnoteContent);
    }
}
See Also