Back to Devexpress

FieldCollection.Unlink() Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-fieldcollection-a45a52f9.md

latest9.8 KB
Original Source

FieldCollection.Unlink() Method

Replaces all fields in the collection with field values.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
void Unlink()
vb
Sub Unlink

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).

csharp
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();
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
'...

Using wordProcessor As New RichEditDocumentServer()
  ' Access a document.
  Dim document As Document = wordProcessor.Document
  '...
  ' Unlink all fields in the main document body.
  document.Fields.Unlink()
End Using

The following example unlinks all fields in text boxes:

csharp
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();
        }
    }
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
'...

Using wordProcessor As New RichEditDocumentServer()
    ' Access a document.
    Dim document As Document = wordProcessor.Document

    ' Check all shapes in the document.
    For Each shape As Shape In document.Shapes

        ' Check whether the shape is a text box.
        If shape.ShapeFormat.HasText Then

            ' Access text box content.
            Dim textBoxDocument As SubDocument = shape.ShapeFormat.TextBox.Document
            '...
            ' Unlink all fields in the text box.
            textBoxDocument.Fields.Unlink()
        End If
    Next shape
End Using
csharp
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);
        }
    }
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
'...

Using wordProcessor As New RichEditDocumentServer()
    ' Access a document.
    Dim document As Document = wordProcessor.Document
    ' Check all document sections.
    For Each section As Section In document.Sections
        ' Check whether the section has a primary header.
        If section.HasHeader(HeaderFooterType.Primary) Then
            ' Start to edit the document header.
            Dim headerContent As SubDocument = section.BeginUpdateHeader()
            '...
            ' Unlink all fields in the document header.
            headerContent.Fields.Unlink()
            ' Finalize to edit the document header.
            section.EndUpdateHeader(headerContent)
        End If

        ' Check whether the section has a primary footer.
        If section.HasFooter(HeaderFooterType.Primary) Then
            ' Start to edit the document footer.
            Dim footerContent As SubDocument = section.BeginUpdateFooter()
            '...
            ' Unlink all fields in the document footer.
            footerContent.Fields.Unlink()
            ' Finalize to edit the document footer.
            section.EndUpdateFooter(footerContent)
        End If
    Next section
End Using
csharp
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);
    }
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
'...

Using wordProcessor As New RichEditDocumentServer()
  ' Access a document.
    Dim document As Document = wordProcessor.Document
  ' Check all document comments.
  For Each comment As Comment In document.Comments
    ' Access comment content.
    Dim commentContent As SubDocument = comment.BeginUpdate()
    '...
    ' Unlink all fields in the comment.
    commentContent.Fields.Unlink()
    ' Finalize to edit the comment.
    comment.EndUpdate(commentContent)
  Next comment
End Using
csharp
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);
    }
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
'...

Using wordProcessor As New RichEditDocumentServer()
    ' Access a document.
    Dim document As Document = wordProcessor.Document
' Check all document footnotes.
    For Each footnote As Note In document.Footnotes
        ' Access footnote content.
        Dim footnoteContent As SubDocument = footnote.BeginUpdate()
        '...
        ' Unlink all fields in the footnote.
        footnoteContent.Fields.Unlink()
        ' Finalize to edit the footnote.
        footnote.EndUpdate(footnoteContent)
    Next footnote

    ' Check all document endnotes.
    For Each endnote As Note In document.Endnotes
        ' Access endnote content.
        Dim endnoteContent As SubDocument = endnote.BeginUpdate()
        '...
        ' Unlink all fields in the endnote.
        endnoteContent.Fields.Unlink()
        ' Finalize to edit the endnote.
        endnote.EndUpdate(endnoteContent)
    Next endnote
End Using

See Also

FieldCollection Interface

FieldCollection Members

DevExpress.XtraRichEdit.API.Native Namespace