GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API.

Read Word Form Controls in C# and VB.NET

After user has filled-in the form, it is time to read user's filled-in values.

GemBox.Document supports reading form field values from DOC and DOCX formats and tries to convert values to CLR type most appropriate for the given form field type.

Following example shows how GemBox.Document reads form fields data.

Screenshot
Read Form Screenshot

See the full code below, use Run Example to execute.

Upload your file(Drag files here)

Download a sample file

using System;
using System.Globalization;
using System.Text;
using GemBox.Document;
using GemBox.Document.Tables;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = DocumentModel.Load("FormFilled.docx");

        // Get a snapshot of all form fields in the document.
        var formFieldsData = document.Content.FormFieldsData;

        var sb = new StringBuilder();

        // Write header.
        sb.AppendLine("Document contains following form fields:");
        sb.AppendFormat(CultureInfo.InvariantCulture,
            "{0,-16}|{1,20} = {2,-20}|({3})",
            "Type",
            '"' + "Name" + '"',
            "Value",
            "Value type").
            AppendLine().AppendLine(new string('-', 78));

        // Write type, name, value and value type of each form field in the document.
        foreach (var formFieldData in formFieldsData)
            sb.AppendFormat(CultureInfo.InvariantCulture,
                "{0,-16}|{1,20} = {2,-20}|({3})",
                formFieldData.GetType().Name,
                '"' + formFieldData.Name + '"',
                formFieldData.Value,
                formFieldData.Value != null ? formFieldData.Value.GetType().FullName : "null").
                AppendLine();

        Console.WriteLine(sb.ToString());
    }
}
Imports System
Imports System.Globalization
Imports System.Text
Imports GemBox.Document
Imports GemBox.Document.Tables

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As DocumentModel = DocumentModel.Load("FormFilled.docx")

        ' Get a snapshot of all form fields in the document.
        Dim formFieldsData = document.Content.FormFieldsData

        Dim sb = New StringBuilder()

        ' Write header.
        sb.AppendLine("Document contains following form fields:")
        sb.AppendFormat(CultureInfo.InvariantCulture,
            "{0,-16}|{1,20} = {2,-20}|({3})",
            "Type",
            """"c + "Name" + """"c,
            "Value",
            "Value type").
            AppendLine().AppendLine(New String("-"c, 78))

        ' Write type, name, value and value type of each form field in the document.
        For Each formFieldData In formFieldsData
            sb.AppendFormat(CultureInfo.InvariantCulture,
                "{0,-16}|{1,20} = {2,-20}|({3})",
                formFieldData.GetType().Name,
                """"c + formFieldData.Name + """"c,
                formFieldData.Value,
                If(formFieldData.Value IsNot Nothing, formFieldData.Value.GetType().FullName, "null")).
                AppendLine()
        Next

        Console.WriteLine(sb.ToString())

    End Sub

End Module

Check next sample.