Products Technologies Demo Docs Blog Support Company

How to Import and Read Form Fields from DOCX Documents in .NET on Linux

Learn how to import and read form fields from DOCX documents in .NET on Linux using TX Text Control. This article provides a step-by-step guide to help you get started with form fields in TX Text Control.

How to Import and Read Form Fields from DOCX Documents in .NET on Linux

Microsoft Word form fields, such as content controls and legacy form fields, are widely used to create interactive documents for data entry, templates, and workflows. Users can input structured data directly within Word documents with these fields, which are commonly used in contract automation, surveys, and forms.

Building cross-platform .NET applications can be challenging, especially when working with form fields, especially on Linux systems. Fortunately, TX Text Control provides a powerful, consistent API that allows you to import, access, and manipulate both content controls (structured document tags) and legacy form fields in DOCX documents across platforms, including Linux.

What Are MS Word Form Fields?

Microsoft Word supports two main types of form fields:

  • Legacy Form Fields:: These are the basic fields used in older versions of Word, such as text inputs, checkboxes, and dropdowns.
  • Content Controls:: These were introduced in later versions of Word and offer a more structured, XML-based approach to embedding data in documents.

TX Text Control provides seamless support for both formats through a unified API, making it easy to programmatically create, read, and manipulate form fields in your .NET applications.

How to Work with Form Fields in TX Text Control

When loading a document, the ApplicationFieldFormat property can be used for specification of how a field is imported. Three relevant options can be specified when importing fields.

  • None: Text fields supported by other applications are not imported as ApplicationFields. Form fields are imported as TX Text Control FormFields.
  • MSWord: Fields that are supported and defined by Microsoft Word are imported as ApplicationFields. The ApplicationFieldTypeNames property can be used to select specific types of fields.
  • MSWordTXFormFields: Fields that are supported and defined by Microsoft Word are imported as ApplicationFields, with the exception of form fields. Form fields such as combo boxes, check boxes, and form text fields are imported as TX Text Control FormField.

By using MSWordTXFormFields, all legacy and content control form fields are automatically converted into TX Text Control form fields.

Now, let's take a look at a document that contains both content control form fields and older, legacy form fields.

DOCX (Office Open XML) form fields in TX Text Control

Accessing Form Fields

Looping through all fields is simple. We just need to load the document with the specific LoadSettings and access the FormFieldCollection.

using TXTextControl;

var loadSettings = new LoadSettings
{
    ApplicationFieldFormat = ApplicationFieldFormat.MSWordTXFormFields
};

using var serverTextControl = new ServerTextControl();
serverTextControl.Create();
serverTextControl.Load("document.docx", StreamType.WordprocessingML, loadSettings);

Console.WriteLine("Form Fields in the document:");

foreach (var field in serverTextControl.FormFields)
{
    switch (field)
    {
        case TextFormField textField:
            Console.WriteLine($"TextFormField: {textField.Text}");
            break;

        case CheckFormField checkBox:
            Console.WriteLine($"CheckFormField: {checkBox.Checked}");
            break;

        case DateFormField dateField:
            Console.WriteLine($"DateFormField: {dateField.Date}");
            break;

        case SelectionFormField selectionField:
            var selectedItem = selectionField.Items.ElementAtOrDefault(selectionField.SelectedIndex);
            Console.WriteLine($"SelectionFormField: {selectedItem}");
            break;
    }
}

In this example, we load a DOCX document that contains both content control form fields and legacy form fields. The document is loaded with the MSWordTXFormFields setting, which converts all form fields into TX Text Control form fields.

The following results are printed to the console:

Form Fields in the document:
TextFormField: Content Control Text

CheckFormField: True
SelectionFormField: Item2
DateFormField: 5/8/2025 12:00:00 AM
TextFormField: Text1
CheckFormField: False

Both form field types are accessible in the unified form field provided by the TX Text Control.

Conclusion

TX Text Control provides a powerful API for working with form fields in .NET applications, regardless of the platform. By using the MSWordTXFormFields setting, you can easily convert and access both content control and legacy form fields in your documents.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

ASP.NETASP.NET CoreDOCX

How to Programmatically Create MS Word DOCX Documents with .NET C# on Linux

Learn how to programmatically create MS Word DOCX documents using .NET C# on Linux with TX Text Control. This tutorial covers the necessary steps to set up your environment and create a simple…


ASP.NETASP.NET CoreDOCX

Edit MS Word DOCX Files in .NET C# and ASP.NET Core

This article shows how to edit MS Word DOCX files in .NET C# and ASP.NET Core using the TX Text Control Document Editor and also how to manipulate documents without a user interface using the…


ASP.NETASP.NET CoreDOC

Create Word Document with .NET C#

This article provides a guide on using TX Text Control to create MS Word DOCX and DOC documents in .NET applications, such as ASP.NET Core and Windows applications. It covers steps to set up a…


ASP.NETASP.NET CoreDOCX

Convert MS Word DOCX to PDF including Text Reflow using .NET C# on Linux

This article explains how to use TX Text Control .NET Server to convert a Microsoft Word DOCX document to a PDF file on a Linux system using .NET C#. This conversion process includes text reflow,…


ASP.NETASP.NET CoreDOCX

Use MailMerge in .NET on Linux to Generate Pixel-Perfect PDFs from DOCX…

This article explores how to use the TX Text Control MailMerge feature in .NET applications on Linux to generate pixel-perfect PDFs from DOCX templates. This powerful combination enables…