Forums     Knowledge Base     OfficeWriter Online     
 
 
This documentation is for
OfficeWriter v3.8.1
.NET Platform

View Docs for Another
Version or Platform

Programmer's Reference > WordApplication API > Field

The Field Object

     extends Element



This class is a low level representation of a field. This encompasses many objects in Word, such as merge fields, hyperlinks, TOC entries, etc. Fields are the generic form of what are contained in a Element's inline elements.

To create a field, call the corresponding "insert" method for what you want to create (hyperlink, TOC entry, etc) on an Element or Position object.

To get an existing field, use the Element.getChildren() method and check which elements are of type Element.Type.Field.

The following sample demonstrates creating a field at the end of a new document and retrieving the first field of an existing document.



Examples:

[csharp]
// Insert a field at the end of a new document
WordApplication app = new WordApplication();
Document doc = app.Create();
Field fld = doc.InsertHyperlinkAfter("http://www.softartisans.com", "SoftArtisans");

// Get the first field of an existing document
WordApplication app = new WordApplication();
Document doc = app.Open(@"C:\sample.doc");
Field firstField = doc.Elements(Element.Type.Field)[0];
[vbnet]
' Insert a field at the end of a new document
Dim app As New WordApplication()
Dim doc As Document = app.Create()
Dim fld As Field = doc.InsertHyperlinkAfter("http://www.softartisans.com", "SoftArtisans")

' Get the first field of an existing document
Dim app As New WordApplication()
Dim doc As Document = app.Open("C:\sample.doc")
Dim firstField As Field = doc.Elements(Element.Type.Field)(0)


Please note that this object inherits methods and properties not shown here from the following objects:

Field Enumerations

NameDescription
Field.FieldType

The Field class is a general representation that encompasses many Word objects, including merge fields, hyperlinks, and table of contents items



Field Properties

Property Type Access Description
Code String read

Returns a String that represents this field's code

Contents Element read

Returns an Element object that represents the contents of this field

Type Field.FieldType read

Returns a Field.FieldType object that represents this field's type



Field Methods

ReturnsSignature and Description
void Update ( )

Updates the value of the field



Copyright 2007 © SoftArtisans, Inc. All Rights Reserved.