Field Class
Represents a Microsoft Word document field.
Inheritance Hierarchy
SystemObject
  Aspose.Words.FieldsField
    More...

Namespace: Aspose.Words.Fields
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.11
Syntax
public class Field

The Field type exposes the following members.

Properties
  NameDescription
Public propertyCode exampleDisplayResult
Gets the text that represents the displayed field result.
Public propertyCode exampleEnd
Gets the node that represents the field end.
Public propertyCode exampleFormat
Gets a FieldFormat object that provides typed access to field's formatting.
Public propertyCode exampleIsDirty
Gets or sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.
Public propertyCode exampleIsLocked
Gets or sets whether the field is locked (should not recalculate its result).
Public propertyCode exampleLocaleId
Gets or sets the LCID of the field.
Public propertyCode exampleResult
Gets or sets text that is between the field separator and field end.
Public propertyCode exampleSeparator
Gets the node that represents the field separator. Can be null.
Public propertyCode exampleStart
Gets the node that represents the start of the field.
Public propertyCode exampleType
Gets the Microsoft Word field type.
Methods
  NameDescription
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodCode exampleGetFieldCode
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.
Public methodCode exampleGetFieldCode(Boolean)
Returns text between field start and field separator (or field end if there is no separator).
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Protected methodNeedStoreOldResultNodes
Public methodCode exampleRemove
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.
Public methodToString (Inherited from Object.)
Public methodCode exampleUnlink
Performs the field unlink.
Public methodCode exampleUpdate
Performs the field update. Throws if the field is being updated already.
Public methodCode exampleUpdate(Boolean)
Performs a field update. Throws if the field is being updated already.
Remarks

A field in a Word document is a complex structure consisting of multiple nodes that include field start, field code, field separator, field result and field end. Fields can be nested, contain rich content and span multiple paragraphs or sections in a document. The Field class is a "facade" object that provides properties and methods that allow to work with a field as a single object.

The Start, Separator and End properties point to the field start, separator and end nodes of the field respectively.

The content between the field start and separator is the field code. The content between the field separator and field end is the field result. The field code typically consists of one or more Run objects that specify instructions. The processing application is expected to execute the field code to calculate the field result.

The process of calculating field results is called the field update. Aspose.Words can update field results of most of the field types in exactly the same way as Microsoft Word does it. Most notably, Aspose.Words can calculate results of even the most complex formula fields. To calculate the field result of a single field use the Update method. To update fields in the whole document use UpdateFields.

You can get the plain text version of the field code using the GetFieldCode(Boolean) method. You can get and set the plain text version of the field result using the Result property. Both the field code and field result can contain complex content, such as nested fields, paragraphs, shapes, tables and in this case you might want to work with the field nodes directly if you need more control.

You do not create instances of the Field class directly. To create a new field use the InsertField(String) method.

Examples
Inserts a field into a document using DocumentBuilder and FieldCode.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a simple Date field into the document.
// When we insert a field through the DocumentBuilder class we can get the
// special Field object which contains information about the field.
Field dateField = builder.InsertField(@"DATE \* MERGEFORMAT");

// Update this particular field in the document so we can get the FieldResult.
dateField.Update();

// Display some information from this field.
// The field result is where the last evaluated value is stored. This is what is displayed in the document
// When field codes are not showing.
Console.WriteLine("FieldResult: {0}", dateField.Result);

// Display the field code which defines the behavior of the field. This can been seen in Microsoft Word by pressing ALT+F9.
Console.WriteLine("FieldCode: {0}", dateField.GetFieldCode());

// The field type defines what type of field in the Document this is. In this case the type is "FieldDate" 
Console.WriteLine("FieldType: {0}", dateField.Type);

// Finally let's completely remove the field from the document. This can easily be done by invoking the Remove method on the object.
dateField.Remove();
See Also
Inheritance Hierarchy
SystemObject
  Aspose.Words.FieldsField
    Aspose.Words.FieldsFieldAddIn
    Aspose.Words.FieldsFieldAddressBlock
    Aspose.Words.FieldsFieldAdvance
    Aspose.Words.FieldsFieldAsk
    Aspose.Words.FieldsFieldAuthor
    Aspose.Words.FieldsFieldAutoNum
    Aspose.Words.FieldsFieldAutoNumLgl
    Aspose.Words.FieldsFieldAutoNumOut
    Aspose.Words.FieldsFieldAutoText
    Aspose.Words.FieldsFieldAutoTextList
    Aspose.Words.FieldsFieldBarcode
    Aspose.Words.FieldsFieldBibliography
    Aspose.Words.FieldsFieldBidiOutline
    Aspose.Words.FieldsFieldCitation
    Aspose.Words.FieldsFieldComments
    Aspose.Words.FieldsFieldCompare
    Aspose.Words.FieldsFieldCreateDate
    Aspose.Words.FieldsFieldData
    Aspose.Words.FieldsFieldDatabase
    Aspose.Words.FieldsFieldDate
    Aspose.Words.FieldsFieldDde
    Aspose.Words.FieldsFieldDdeAuto
    Aspose.Words.FieldsFieldDisplayBarcode
    Aspose.Words.FieldsFieldDocProperty
    Aspose.Words.FieldsFieldDocVariable
    Aspose.Words.FieldsFieldEditTime
    Aspose.Words.FieldsFieldEmbed
    Aspose.Words.FieldsFieldEQ
    Aspose.Words.FieldsFieldFileName
    Aspose.Words.FieldsFieldFileSize
    Aspose.Words.FieldsFieldFillIn
    Aspose.Words.FieldsFieldFootnoteRef
    Aspose.Words.FieldsFieldFormCheckBox
    Aspose.Words.FieldsFieldFormDropDown
    Aspose.Words.FieldsFieldFormText
    Aspose.Words.FieldsFieldFormula
    Aspose.Words.FieldsFieldGlossary
    Aspose.Words.FieldsFieldGoToButton
    Aspose.Words.FieldsFieldGreetingLine
    Aspose.Words.FieldsFieldHyperlink
    Aspose.Words.FieldsFieldIf
    Aspose.Words.FieldsFieldImport
    Aspose.Words.FieldsFieldInclude
    Aspose.Words.FieldsFieldIncludePicture
    Aspose.Words.FieldsFieldIncludeText
    Aspose.Words.FieldsFieldIndex
    Aspose.Words.FieldsFieldInfo
    Aspose.Words.FieldsFieldKeywords
    Aspose.Words.FieldsFieldLastSavedBy
    Aspose.Words.FieldsFieldLink
    Aspose.Words.FieldsFieldListNum
    Aspose.Words.FieldsFieldMacroButton
    Aspose.Words.FieldsFieldMergeBarcode
    Aspose.Words.FieldsFieldMergeField
    Aspose.Words.FieldsFieldMergeRec
    Aspose.Words.FieldsFieldMergeSeq
    Aspose.Words.FieldsFieldNext
    Aspose.Words.FieldsFieldNextIf
    Aspose.Words.FieldsFieldNoteRef
    Aspose.Words.FieldsFieldNumChars
    Aspose.Words.FieldsFieldNumPages
    Aspose.Words.FieldsFieldNumWords
    Aspose.Words.FieldsFieldOcx
    Aspose.Words.FieldsFieldPage
    Aspose.Words.FieldsFieldPageRef
    Aspose.Words.FieldsFieldPrint
    Aspose.Words.FieldsFieldPrintDate
    Aspose.Words.FieldsFieldPrivate
    Aspose.Words.FieldsFieldQuote
    Aspose.Words.FieldsFieldRD
    Aspose.Words.FieldsFieldRef
    Aspose.Words.FieldsFieldRevNum
    Aspose.Words.FieldsFieldSaveDate
    Aspose.Words.FieldsFieldSection
    Aspose.Words.FieldsFieldSectionPages
    Aspose.Words.FieldsFieldSeq
    Aspose.Words.FieldsFieldSet
    Aspose.Words.FieldsFieldShape
    Aspose.Words.FieldsFieldSkipIf
    Aspose.Words.FieldsFieldStyleRef
    Aspose.Words.FieldsFieldSubject
    Aspose.Words.FieldsFieldSymbol
    Aspose.Words.FieldsFieldTA
    Aspose.Words.FieldsFieldTC
    Aspose.Words.FieldsFieldTemplate
    Aspose.Words.FieldsFieldTime
    Aspose.Words.FieldsFieldTitle
    Aspose.Words.FieldsFieldToa
    Aspose.Words.FieldsFieldToc
    Aspose.Words.FieldsFieldUnknown
    Aspose.Words.FieldsFieldUserAddress
    Aspose.Words.FieldsFieldUserInitials
    Aspose.Words.FieldsFieldUserName
    Aspose.Words.FieldsFieldXE