Content controls are individual controls that you can add and customize for use in templates, forms, and documents. These controls are commonly used in MS Word templates and forms and replace the old form fields. Both types of form fields are supported by TX Text Control and will be automatically imported and converted to TX Text Control form fields.

Important

Only the Office Open XML (DOCX) format, not the MS Word 97-2003 document format, supports content controls in MS Word documents.

If you are using fields from other applications, such as MS Word, there are a number of ways to handle these fields. When loading a document, the ApplicationFieldFormat TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
LoadSettings Class
ApplicationFieldFormat Property
Specifies the format of text fields which are imported.
property can be used to specify how a field is imported. There are three relevant options that can be specified when importing fields:

Field Overview

The table below shows how fields are imported based on the specified LoadSettings:

Field Document Format Imported as ( LoadSettings TX Text Control .NET for Windows Forms
TXTextControl Namespace
LoadSettings Class
ApplicationFieldFormat Property
Specifies the format of text fields which are imported.
)
None MSWord MSWordTXFormFields
TextField InternalUnicodeFormat, InternalFormat TextField TX Text Control .NET for Windows Forms
TXTextControl Namespace
TextField Class
An instance of the TextField class represents a text field in a Text Control document.
N/A N/A
MergeField MSWord, WordprocessingML, RichTextFormat × ApplicationField TX Text Control .NET for Windows Forms
TXTextControl Namespace
ApplicationField Class
The ApplicationField class supports text field formats of applications such as Microsoft Word.
ApplicationField TX Text Control .NET for Windows Forms
TXTextControl Namespace
ApplicationField Class
The ApplicationField class supports text field formats of applications such as Microsoft Word.
DOCVARIABLE MSWord, WordprocessingML, RichTextFormat × ApplicationField TX Text Control .NET for Windows Forms
TXTextControl Namespace
ApplicationField Class
The ApplicationField class supports text field formats of applications such as Microsoft Word.
ApplicationField TX Text Control .NET for Windows Forms
TXTextControl Namespace
ApplicationField Class
The ApplicationField class supports text field formats of applications such as Microsoft Word.
Content Control MSWord, WordprocessingML, RichTextFormat FormFields TX Text Control .NET for Windows Forms
TXTextControl Namespace
FormField Class
The FormField class is the base class of all form fields.
ApplicationField TX Text Control .NET for Windows Forms
TXTextControl Namespace
ApplicationField Class
The ApplicationField class supports text field formats of applications such as Microsoft Word.
FormFields TX Text Control .NET for Windows Forms
TXTextControl Namespace
FormField Class
The FormField class is the base class of all form fields.
Legacy Form Fields MSWord, WordprocessingML, RichTextFormat FormFields TX Text Control .NET for Windows Forms
TXTextControl Namespace
FormField Class
The FormField class is the base class of all form fields.
ApplicationField TX Text Control .NET for Windows Forms
TXTextControl Namespace
ApplicationField Class
The ApplicationField class supports text field formats of applications such as Microsoft Word.
FormFields TX Text Control .NET for Windows Forms
TXTextControl Namespace
FormField Class
The FormField class is the base class of all form fields.

Importing Content Controls

Consider the following MS Word document to which several Content Controls have been added.

Content Controls in TX Text Control

The following code shows how to load the document with Content Control fields automatically converted to TX Text Control fields.

TXTextControl.LoadSettings loadSettings = new TXTextControl.LoadSettings()
{
ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWordTXFormFields
};
using (TXTextControl.ServerTextControl serverTextControl =
new TXTextControl.ServerTextControl())
{
serverTextControl.Create();
serverTextControl.Load("contentcontrols.docx",
TXTextControl.StreamType.WordprocessingML, loadSettings);
foreach (FormField ff in serverTextControl.FormFields)
{
Console.WriteLine(ff.Text);
}
}
view raw test.cs hosted with ❤ by GitHub

When the document is loaded into a visual TX Text Control, the Content Control fields are rendered as form fields by default.

Content Controls in TX Text Control

Processing Content Controls

Another way to access Content Controls is to import the document without converting them to form fields. In this case, Content Controls are accessible through the ApplicationFields TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
ServerTextControl Class
ApplicationFields Property
Gets a collection of all Microsoft Word or Heiler HighEdit fields that have been created or imported from a Microsoft Word or RTF document.
collection to provide more access to the contained data.

The DocumentServer includes the Fields TX Text Control .NET Server for ASP.NET
DocumentServer.Fields Namespace
TXTextControl.DocumentServer.Fields Namespace
namespace, which contains field classes for retrieving additional data from Content Controls such as Title TX Text Control .NET Server for ASP.NET
DocumentServer.Fields Namespace
ContentControlFieldAdapter Class
Title Property
Gets or sets the content control's title.
or Tag TX Text Control .NET Server for ASP.NET
DocumentServer.Fields Namespace
ContentControlFieldAdapter Class
Tag Property
Gets or sets the content control's tag.
.

The following code shows how to access the Content Controls in the document.

LoadSettings ls = new LoadSettings()
{
ApplicationFieldFormat = ApplicationFieldFormat.MSWord
};
using (ServerTextControl tx = new ServerTextControl())
{
tx.Create();
tx.Load("contentcontrols.docx", StreamType.WordprocessingML, ls);
foreach (ApplicationField af in tx.ApplicationFields)
{
try
{
var tempField = ContentControlFieldAdapter.CreateContentControl(af);
if (tempField is RichTextContentControl ||
tempField is PlainTextContentControl ||
tempField is CheckBoxContentControl ||
tempField is ComboBoxContentControl ||
tempField is DateContentControl ||
tempField is DropDownListContentControl)
{
Console.WriteLine(tempField.Title);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
view raw test.cs hosted with ❤ by GitHub

Conclusion

Content controls are used to create structured documents and forms. This article showed how to import and process content controls in MS Word documents using TX Text Control. TX Text Control supports legacy form fields, merge fields, and Content Control fields, making them easy to import and edit.