Edit this page

Fields

Fields are a convenient way to show non-static data in the document. In this way, you could present different data to the end-user without actually changing the document content.

This topic contains the following sections:

Field Types

In RadDocument the base class for all fields is CodeBasedField. It is an abstract class that can be inherited from. Some of the implemented and ready-to-use field types are:

  • DateField: Inserts the current date in one of the specified formats.

  • PageField: Shows the current page number.

  • NumPagesField: Shows the number of pages in the document.

  • MergeField: Used in mail-merge scenarios. You can read more here: Mail Merge.

  • IncludePictureField: Specifies the URI from which an image must be retrieved.

  • DocumentVariableField А field which uses DocumentVariables. More information can be found here: Document Variables.

  • SequentialField: Tracks the number of tables and figures inserted in the document before a place in the document, so that the InsertCaption() method would use the correct number. Find more here: Captions for Tables and Figures.

  • StyleReferenceField: The type of field that a reference field refers to when a cross-reference to a Heading style is inserted.

  • ReferenceField: Used to refer to a bookmark or other type of field. It is inserted when a cross-reference to a table or figure caption is added to the document. Find more here: Cross-Reference.

  • PageReferenceField: Inserts the page number of a referenced bookmark.

  • HyperlinkField: Inserted in hyperlinks to store information about the navigation URI.

  • TableOfContentsField: Shows a table of contents including headings and other specially marked parts of the document. Also can be configured to show table of figures or table of tables.

  • TCField: Used to mark text that should be included as entry in TableOfContentsField.

  • AuthorField: The type of field is related to track changes, specifies the name of the user that has modified the document part. Read more here: Track Changes.

  • CitationField: Inserted when you add a citation to the document.

  • BibliographyField: Inserted in the document when you want to add information about the bibliographic sources used in the document. Read more here: Bibliographic References.

Display Modes

Fields normally have two modes – Code and Result. When in code mode, they appear as { [] [ ]*}.

For instance, Page Fields appear as { PAGE }, Merge Fields as { MERGEFIELD FirstName } or { MERGEFIELD FirstName \b "text that will appear before the merge field if it is not empty" }.

In result mode, all fields get evaluated depending on some conditions – the place in the document where they appear in the case of page fields, the current mail merge record for merge fields, etc.

MergeFields have one additional mode – DisplayName that shows the property path they use in brackets of the type <<[PropertyPathHere]>>. Furthermore, there are specific methods and commands of the editor that change the display mode of merge fields or even remove them from the document altogether, replacing them with the ResultFragment. More information on this topic can be found in the Mail Merge article.

Inserting a Field

Inserting any type of field in the document of an editor can be done with the InsertField() method.

Insert a page field:

C#

this.radRichTextBox.InsertField(new PageField());

Updating a Field

Update of a field can be triggered from the context menu or using the UpdateField() method by passing the corresponding FieldRangeStart of the field as a parameter.

Update a field:

C#

this.radRichTextBox.UpdateField(fieldRangeStart);

Updating all Fields

You can update all fields in the document with the UpdateAllFields() method of RadRichTextBox. The method is optimized to perform better than updating fields one by one using the Update method.

Correctly updating all fields in a document works in almost all cases, but it’s not always possible as there are multiple dependencies between the fields. You can influence the way UpdateAllFields is executed by registering additional update information for specific field types.

See Also