## FieldRef class

Implements the REF field.

To learn more, visit the [Working with Fields](https://docs.aspose.com/words/net/working-with-fields/) documentation article.

```csharp
public class FieldRef : Field
```

## Constructors

| Name | Description |
| --- | --- |
| [FieldRef](fieldref/)() | The default constructor. |

## Properties

| Name | Description |
| --- | --- |
| [BookmarkName](../../aspose.words.fields/fieldref/bookmarkname/) { get; set; } | Gets or sets the referenced bookmark's name. |
| [DisplayResult](../../aspose.words.fields/field/displayresult/) { get; } | Gets the text that represents the displayed field result. |
| [End](../../aspose.words.fields/field/end/) { get; } | Gets the node that represents the field end. |
| [Format](../../aspose.words.fields/field/format/) { get; } | Gets a [`FieldFormat`](../fieldformat/) object that provides typed access to field's formatting. |
| [IncludeNoteOrComment](../../aspose.words.fields/fieldref/includenoteorcomment/) { get; set; } | Gets or sets whether to increment footnote, endnote, and annotation numbers that are marked by the bookmark, and insert the corresponding footnote, endnote, and comment text. |
| [InsertHyperlink](../../aspose.words.fields/fieldref/inserthyperlink/) { get; set; } | Gets or sets whether to create a hyperlink to the bookmarked paragraph. |
| [InsertParagraphNumber](../../aspose.words.fields/fieldref/insertparagraphnumber/) { get; set; } | Gets or sets whether to insert the paragraph number of the referenced paragraph exactly as it appears in the document. |
| [InsertParagraphNumberInFullContext](../../aspose.words.fields/fieldref/insertparagraphnumberinfullcontext/) { get; set; } | Gets or sets whether to insert the paragraph number of the referenced paragraph in full context. |
| [InsertParagraphNumberInRelativeContext](../../aspose.words.fields/fieldref/insertparagraphnumberinrelativecontext/) { get; set; } | Gets or sets whether to insert the paragraph number of the referenced paragraph in relative context. |
| [InsertRelativePosition](../../aspose.words.fields/fieldref/insertrelativeposition/) { get; set; } | Gets or sets whether to insert the relative position of the referenced paragraph. |
| [IsDirty](../../aspose.words.fields/field/isdirty/) { get; set; } | Gets or sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document. |
| [IsLocked](../../aspose.words.fields/field/islocked/) { get; set; } | Gets or sets whether the field is locked (should not recalculate its result). |
| [LocaleId](../../aspose.words.fields/field/localeid/) { get; set; } | Gets or sets the LCID of the field. |
| [NumberSeparator](../../aspose.words.fields/fieldref/numberseparator/) { get; set; } | Gets or sets the character sequence that is used to separate sequence numbers and page numbers. |
| [Result](../../aspose.words.fields/field/result/) { get; set; } | Gets or sets text that is between the field separator and field end. |
| [Separator](../../aspose.words.fields/field/separator/) { get; } | Gets the node that represents the field separator. Can be `null`. |
| [Start](../../aspose.words.fields/field/start/) { get; } | Gets the node that represents the start of the field. |
| [SuppressNonDelimiters](../../aspose.words.fields/fieldref/suppressnondelimiters/) { get; set; } | Gets or sets whether to suppress non-delimiter characters. |
| virtual [Type](../../aspose.words.fields/field/type/) { get; } | Gets the Microsoft Word field type. |

## Methods

| Name | Description |
| --- | --- |
| [GetFieldCode](../../aspose.words.fields/field/getfieldcode/)() | Returns text between field start and field separator (or field end if there is no separator). Both field code and field result of child fields are included. |
| [GetFieldCode](../../aspose.words.fields/field/getfieldcode/)(*bool*) | Returns text between field start and field separator (or field end if there is no separator). |
| virtual [Remove](../../aspose.words.fields/field/remove/)() | Removes the field from the document. Returns a node right after the field. If the field's end is the last child of its parent node, returns its parent paragraph. If the field is already removed, returns `null`. |
| [Unlink](../../aspose.words.fields/field/unlink/)() | Performs the field unlink. |
| [Update](../../aspose.words.fields/field/update/)() | Performs the field update. Throws if the field is being updated already. |
| [Update](../../aspose.words.fields/field/update/)(*bool*) | Performs a field update. Throws if the field is being updated already. |

## Remarks

Inserts the text or graphics represented by the specified bookmark.

## Examples

Shows how to insert REF fields to reference bookmarks.

```csharp
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.StartBookmark("MyBookmark");
builder.InsertFootnote(FootnoteType.Footnote, "MyBookmark footnote #1");
builder.Write("Text that will appear in REF field");
builder.InsertFootnote(FootnoteType.Footnote, "MyBookmark footnote #2");
builder.EndBookmark("MyBookmark");
builder.MoveToDocumentStart();

// We will apply a custom list format, where the amount of angle brackets indicates the list level we are currently at.
builder.ListFormat.ApplyNumberDefault();
builder.ListFormat.ListLevel.NumberFormat = "> \x0000";

// Insert a REF field that will contain the text within our bookmark, act as a hyperlink, and clone the bookmark's footnotes.
FieldRef field = InsertFieldRef(builder, "MyBookmark", "", "\n");
field.IncludeNoteOrComment = true;
field.InsertHyperlink = true;

Assert.That(field.GetFieldCode(), Is.EqualTo(" REF  MyBookmark \\f \\h"));

// Insert a REF field, and display whether the referenced bookmark is above or below it.
field = InsertFieldRef(builder, "MyBookmark", "The referenced paragraph is ", " this field.\n");
field.InsertRelativePosition = true;

Assert.That(field.GetFieldCode(), Is.EqualTo(" REF  MyBookmark \\p"));

// Display the list number of the bookmark as it appears in the document.
field = InsertFieldRef(builder, "MyBookmark", "The bookmark's paragraph number is ", "\n");
field.InsertParagraphNumber = true;

Assert.That(field.GetFieldCode(), Is.EqualTo(" REF  MyBookmark \\n"));

// Display the bookmark's list number, but with non-delimiter characters, such as the angle brackets, omitted.
field = InsertFieldRef(builder, "MyBookmark", "The bookmark's paragraph number, non-delimiters suppressed, is ", "\n");
field.InsertParagraphNumber = true;
field.SuppressNonDelimiters = true;

Assert.That(field.GetFieldCode(), Is.EqualTo(" REF  MyBookmark \\n \\t"));

// Move down one list level.
builder.ListFormat.ListLevelNumber++;
builder.ListFormat.ListLevel.NumberFormat = ">> \x0001";

// Display the list number of the bookmark and the numbers of all the list levels above it.
field = InsertFieldRef(builder, "MyBookmark", "The bookmark's full context paragraph number is ", "\n");
field.InsertParagraphNumberInFullContext = true;

Assert.That(field.GetFieldCode(), Is.EqualTo(" REF  MyBookmark \\w"));

builder.InsertBreak(BreakType.PageBreak);

// Display the list level numbers between this REF field, and the bookmark that it is referencing.
field = InsertFieldRef(builder, "MyBookmark", "The bookmark's relative paragraph number is ", "\n");
field.InsertParagraphNumberInRelativeContext = true;

Assert.That(field.GetFieldCode(), Is.EqualTo(" REF  MyBookmark \\r"));

// At the end of the document, the bookmark will show up as a list item here.
builder.Writeln("List level above bookmark");
builder.ListFormat.ListLevelNumber++;
builder.ListFormat.ListLevel.NumberFormat = ">>> \x0002";

doc.UpdateFields();
doc.Save(ArtifactsDir + "Field.REF.docx");
```

Shows how to insert REF fields to reference bookmarks (InsertFieldRef).

```csharp
/// <summary>
/// Get the document builder to insert a REF field, reference a bookmark with it, and add text before and after it.
/// </summary>
private static FieldRef InsertFieldRef(DocumentBuilder builder, string bookmarkName, string textBefore, string textAfter)
{
    builder.Write(textBefore);
    FieldRef field = (FieldRef)builder.InsertField(FieldType.FieldRef, true);
    field.BookmarkName = bookmarkName;
    builder.Write(textAfter);
    return field;
}
```

Shows how to create bookmarked text with a SET field, and then display it in the document using a REF field.

```csharp
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Name bookmarked text with a SET field. 
// This field refers to the "bookmark" not a bookmark structure that appears within the text, but a named variable.
FieldSet fieldSet = (FieldSet)builder.InsertField(FieldType.FieldSet, false);
fieldSet.BookmarkName = "MyBookmark";
fieldSet.BookmarkText = "Hello world!";
fieldSet.Update();

Assert.That(fieldSet.GetFieldCode(), Is.EqualTo(" SET  MyBookmark \"Hello world!\""));

// Refer to the bookmark by name in a REF field and display its contents.
FieldRef fieldRef = (FieldRef)builder.InsertField(FieldType.FieldRef, true);
fieldRef.BookmarkName = "MyBookmark";
fieldRef.Update();

Assert.That(fieldRef.GetFieldCode(), Is.EqualTo(" REF  MyBookmark"));
Assert.That(fieldRef.Result, Is.EqualTo("Hello world!"));

doc.Save(ArtifactsDir + "Field.SET.REF.docx");
```

### See Also

* class [Field](../field/)
* namespace [Aspose.Words.Fields](../../aspose.words.fields/)
* assembly [Aspose.Words](../../)
