How to Use the FieldAdapter Classes to Manipulate ApplicationFields
TX Text Control .NET for Windows Forms 14.0 introduced the ApplicationField class to manipulate MS Word standard fields like MergeField, Date or NumPages. All switches and parameters of these fields are represented by the Parameters property which gets or sets a string array of the available values. In order to create or edit such fields, you need to know the structure of these standard fields. In version 15.0, we introduced the FieldAdapter classes for the most commonly used fields:…

TX Text Control .NET for Windows Forms 14.0 introduced the ApplicationField class to manipulate MS Word standard fields like MergeField, Date or NumPages. All switches and parameters of these fields are represented by the Parameters property which gets or sets a string array of the available values.
In order to create or edit such fields, you need to know the structure of these standard fields. In version 15.0, we introduced the FieldAdapter classes for the most commonly used fields:
- MergeField
- DateField
- IfField
- IncludeText
- FormCheckbox
- FormDropDown
- FormText
These adapter classes can be used to create or manipulate these MS Word compatible fields without learning the specific switches and possible parameters. All settings can be easily accessed using the available properties.
Let's have a look at a typical MergeField:
{MERGEFIELD company \* Upper \b "Company:" \* MERGEFORMAT}
The following illustration shows this field in MS Word with a description of each parameter:

By accesssing this field using the ApplicationFields, the Parameter property would return this string array:
{ "company", "\* Upper", "\b \"Company\"", "\* MERGEFORMAT" }
How does the FieldAdapter comes into play?
As the name implies, FieldAdapter is an adapter for the ApplicationFields. It can be only used in combination with these fields. To manipulate a MergeField, the MergeField adapter should be used. To create a new instance of the MergeField, the specific ApplicationField can be passed in the constructor:
foreach (TXTextControl.ApplicationField field in textControl1.ApplicationFields)
{
if(field.TypeName == "MERGEFIELD")
{
TXTextControl.DocumentServer.Fields.MergeField mergeField =
new TXTextControl.DocumentServer.Fields.MergeField(field);
mergeField.Name = "companyname";
}
}
In the above code, we check the TypeName of the field. If it is a MergeField, a new instance of the adapter class is created and the ApplicationField is passed in the constructor. After that, we have access to the specific MergeField properties like the Name. You can use the FieldAdapter to insert new fields as well:
TXTextControl.DocumentServer.Fields.MergeField mergeField =
new TXTextControl.DocumentServer.Fields.MergeField();
textControl1.ApplicationFields.Add(mergeField.ApplicationField);
Summary: Using the FieldAdapters, you can easily handle the most commonly used fields of MS Word. You don't need to care about parsing the parameters on your own. You get a full set of properties for each available setting.
Related Posts
Getting Started: ServerTextControl and MailMerge in a .NET 8 Console…
This article shows how to create a .NET 8 console application on Linux using Docker and WSL that uses the ServerTextControl to create a document and MailMerge to merge JSON data into the document.…
Create a Table of Contents in Windows Forms using C#
This article explains how to create a table of contents in Windows Forms using the ribbon or programmatically. Creating a table of contents is required to organize large documents.
Two Ways to Restart Numbered Lists in TX Text Control
In TX Text Control, numbered lists are continued by default and need to be reset when required. There is more than one way if you want to restart numbered lists in a document. In this article, two…
Inserting MS Word Compatible FORMCHECKBOX Fields
Checkboxes are probably the most commonly used selection elements in paper and web-based forms and questionnaires. Inspired by a customer's project, I built a small sample that shows how to insert…
Inserting and Processing MS Word Compatible DATE Fields
A date field can be very helpful in mail-merge templates to include the current valid date in an appropriate format. TX Text Control .NET for Windows Forms provides fully compatible fields to…