Nevron Open Vision Documentation
Field Inlines

Field inline elements (fields) are inline elements that can be automatically populated with text from the control. Examples of such elements are page number and count in header / footer elements, current date/time field etc. Fields are represented by instances of the NFieldInline class. The following sections discuss how to work with fields.


This topic contains these sections:
Creating Fields

The following code snippet shows how to create a simple header that contains an automatically populated page number field:

Creating Field Inline Elements
Copy Code
NSection section = new NSection();

NHeaderFooter header = new NHeaderFooter();

NParagraph paragraph = new NParagraph();
paragraph.Inlines.Add(new NTextInline("Page Number:"));
paragraph.Inlines.Add(new NFieldInline(ENNumericFieldName.PageNumber));
header.Blocks.Add(paragraph);

section.Header = header;
section.Blocks.Add(new NParagraph("Section Text..."));

m_RichText.Content.Sections.Clear();
m_RichText.Content.Sections.Add(section);

The NFieldInline class has a property called Value which accepts objects derived from the NFieldValue abstract class. In the code above we used a shorthand constructor to create a field with a numeric field value.

Note that only the following field values are updated automatically when you insert / remove inlines that reference them:

For the rest of the field values you need to call the NFieldInline method Update to update the text contained in the field:

Updating Field Values
Copy Code
someFieldInline.Update(); // update the value of the field
The field must be part of a document when you call its Update method.

Numeric Field Values

Numeric field values are represented by instances of the NNumericFieldValue class. The following code snippet shows how to create a field and modify its field value to numeric:

Creating Numeric Field Values
Copy Code
NFieldInline fieldInline = new NFieldInline();

NNumericFieldValue numericFieldValue = new NNumericFieldValue();
numericFieldValue.FieldName = ENNumericFieldName.PageNumber;

fieldInline.Value = numericFieldValue;

The following table shows the field names accepted by the FieldName property:

ENNumericFieldName Description
AutoNumber Automatic number. Each successive occurrence of a field using this field value will display with the next number. For example the first one will display 1, the second 2 and so on. The automatic number is shared between all fields with auto number value found in the same root (document, header or footer).
EditTime The total editing time in minutes since the document was created.
FileSize The file size of the document that produced this document (in bytes).
NumberOfChars Number of chars in the document.
PageCount The total number of pages in the document. This field has different values depending on the document layout. In Web and Normal layout it has an estimated value.
NumberOfWords Number of words in the document.
PageNumber Current page number. This field has different values depending on the document layout. In Web and Normal layout it has an estimated value.
SectionNumber The number of the section that contains the field inline referencing this feld value.
SectionPageNumber The number of the page containing this inline, counting from the first page generated by the section that contains the inline.
SectionPageCount Number of pages produced by the section that contains the inline.

In addition the NNumericFieldValue has a property called format that allows you to specify formatting for the referenced field value. The format property accepts all valid .NET numeric format strings.

Date / Time Field Values

Date / Time field values are represented by instances of the NDateTimeFieldValue class. The following code snippet shows how to create a field and modify its field value to date / time:

Creating Date / Time Field Values
Copy Code
NSection section = new NSection();

NParagraph paragraph = new NParagraph();
paragraph.Inlines.Add(new NTextInline("Current Date / Time:"));

NFieldInline fieldInline = new NFieldInline();

NDateTimeFieldValue dateTimeFieldValue = new NDateTimeFieldValue();
dateTimeFieldValue.FieldName = ENDateTimeFieldName.CurrentDate;

fieldInline.Value = dateTimeFieldValue;
paragraph.Inlines.Add(fieldInline);

section.Blocks.Add(paragraph);

m_RichText.Content.Sections.Clear();
m_RichText.Content.Sections.Add(section);

fieldInline.Update();

The following table shows the available date / time field values:

ENDateTimeFieldName Description
CreationDate The document creation date
CurrentDate The current date
PrintDate The last print date
SavedDate The last saved date

Similarly to the NNumericFieldValue the NDateTimeFieldValue has a property called Format that accepts any valid .NET date / time formatting string and allows you to alter the formatting of the date / time value.

String Field Values

String field values are represented by instances of the NStringFieldValue class. The following code snippet shows how to reference the Author field name from the document information properties:

Creating String Field Values
Copy Code
NSection section = new NSection();

NParagraph paragraph = new NParagraph();
paragraph.Inlines.Add(new NTextInline("Author: "));

NFieldInline fieldInline = new NFieldInline();

NStringFieldValue stringFieldValue = new NStringFieldValue();
stringFieldValue.FieldName = ENStringFieldName.Author;
stringFieldValue.Format = ENStringFieldValueFormat.UpperCase;

fieldInline.Value = stringFieldValue;
paragraph.Inlines.Add(fieldInline);

section.Blocks.Add(paragraph);

m_RichText.Content.Information.Author = "Nevron Software";
m_RichText.Content.Sections.Clear();
m_RichText.Content.Sections.Add(section);

fieldInline.Update();

The following table lists the field names you can use with this field value:

ENStringFieldName Description
Author The value of the Author field in the document information properties.
Comment The value of the Comment field in the document information properties.
FileName The document file name.
Keywords The value of the Keywords field in the document information properties.
LastSavedBy The name of the last person that saved the document.
Subject The value of the Subject field in the document information properties.
Title The title of the document.

The Format property of the NStringValueValue class accepts values from the ENStringFieldValueFormat which allows you to apply simple text transformations on the field value. The following table lists the available options:

ENStringFieldValueFormat Description
None No transformation is applied
UpperCase All letters become upper case
LowerCase All letters become lower case
FirstUpper First letter becomes capital (upper) all other chars become lower case
Caps All first word letters become capital, all other letters become lower case
See Also
Send Feedback