Products Technologies Demo Docs Blog Support Company

MS Word Content Controls Field Adapter Classes

This article is obsolete. The field adapter classes have been implemented in the DocumentServer namespace directly: TXTextControl.DocumentServer.Fields.FieldAdapter class ? TX Text Control .NET for Windows Forms ? DocumentServer.Fields Namespace ? FieldAdapter Class The abstract FieldAdapter class is the base class of all special DocumentServer field adapters. The sample code is usable and is migrated to the new integrated classes. In Microsoft Word, Content Controls are controls that can be…

MS Word Content Controls Field Adapter Classes

This article is obsolete. The field adapter classes have been implemented in the DocumentServer namespace directly:

TXTextControl.DocumentServer.Fields.FieldAdapter class

The sample code is usable and is migrated to the new integrated classes.

In Microsoft Word, Content Controls are controls that can be added and customized for use in documents and templates. Those controls provide properties and settings that can be used to automate documents.

When loading a document in the Office Open XML format, Content Controls are available through the ApplicationFieldCollection and its ApplicationField objects.

The Parameters property contains the pure Office Open XML data of those fields.

The TXTextControl.DocumentServer.Fields namespace already provides field adapter for merge and form fields. Now, we published complete adapter classes for the following content controls:

  • RichTextContentControl
  • PlainTextContentControl
  • CheckBoxContentControl
  • ComboBoxContentControl
  • DateContentControl
  • DropDownContentControl

Using the adapter classes, you can create new content control fields or manipulate content control fields without any knowledge of the specific Office Open XML format.

Those classes extend the existing namespace TXTextControl.DocumentServer.Fields:

In order to create a new CheckBoxContentControl, simply create a new adapter field and add its ApplicationField to TextControl:

CheckBoxContentControl checkbox = new CheckBoxContentControl();
checkbox.Checked = true;

textControl1.ApplicationFields.Add(checkbox.ApplicationField);

To manipulate an existing Content Control field, the adapter field class can be created with the existing ApplicationField in the constructor:

foreach (ApplicationField field in textControl1.ApplicationFields)
{
    Type type = ContentControlFieldAdapter.GetContentControlType(field);

    // based on the type, create a new ContentControl object and
    // display some field information in a MessageBox
    switch (type.Name)
    {
        case "RichTextContentControl":
            RichTextContentControl rtb = new RichTextContentControl(field);

            MessageBox.Show(
                "RichTextContentControl:
Text: " + rtb.Text + "
" +
                "Title: " + rtb.Title + "
" +
                "Tag: " + rtb.Tag + "
");
            break;
        // ...
    }
}

Download the sample from GitHub and test it on your own.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

GitHub

Download and Fork This Sample on GitHub

We proudly host our sample code on github.com/TextControl.

Please fork and contribute.

Download ZIP

Open on GitHub

Open in Visual Studio

Requirements for this sample

  • Visual Studio 2017 or better
  • TX Text Control .NET for Windows Forms (trial sufficient)

Reporting

The Text Control Reporting Framework combines powerful reporting features with an easy-to-use, MS Word compatible word processor. Users can create documents and templates using ordinary Microsoft Word skills. The Reporting Framework is included in all .NET based TX Text Control products including ASP.NET, Windows Forms and WPF.

See Reporting products

Related Posts

ASP.NETReportingHTML5

Creating Your First ASP.NET Reporting Application

This tutorial shows how to use the MailMerge component in an ASP.NET Web application to merge a template with data to create an Adobe PDF document.


ASP.NETReportingTutorial

New Online Sample: Build your First Report

We published a new online demo that shows how to create a report including preparing data, creating a template to merging them together.


ReportingDocumentationReportingCloud

Create your First Document with ReportingCloud

As part of our new ReportingCloud documentation, we published a guided tutorial that shows how to create a document without programming.


CloudReportingMail Merge

MailMerge: Starting Each Merge Block on a New Page

A merge block is repeated based on the number of matching data rows in the hierarchical data object. The complete merge block is cloned and inserted under the original location in the template.…


ReportingTutorialWeb API

Using MailMerge with JSON Data

In the last article, we explained how to create an ASP.NET Web API to merge templates with JSON data in the payload body of an HTTP request. The focus of this article was on the Web API and…