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.

Update Word Form Controls in C# and VB.NET

GemBox.Document supports writing and updating form field values.

The following example shows how to write or modify values of an existing form fields in a document. When setting the FormTextData.Value to IFormattable type (like Double or DateTime), the field's resulting text will depend on the value of the FormTextData.ValueFormat.

Screenshot
Update 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 formData = document.Content.FormFieldsData;

        // Update "FullName" text box field.
        FormTextData fullNameData = (FormTextData)formData["FullName"];
        fullNameData.Value = "Jane Doe";

        // Update "BirthDate" text box field.
        FormTextData birthDateData = (FormTextData)formData["BirthDate"];
        birthDateData.Value = new DateTime(2000, 1, 1);

        // Update "Salary" text box field.
        FormTextData salaryData = (FormTextData)formData["Salary"];
        salaryData.Value = 5432.1;

        // Check "Married" check box field.
        FormCheckBoxData marriedData = (FormCheckBoxData)formData["Married"];
        marriedData.Value = true;

        // Select "Female" from drop down field.
        FormDropDownData genderData = (FormDropDownData)formData["Gender"];
        genderData.SelectedItemIndex = genderData.Items.IndexOf("Female");

        document.Save("Update Form.docx");
    }
}
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 formData = document.Content.FormFieldsData

        ' Update "FullName" text box field.
        Dim fullNameData As FormTextData = DirectCast(formData("FullName"), FormTextData)
        fullNameData.Value = "Jane Doe"

        ' Update "BirthDate" text box field.
        Dim birthDateData As FormTextData = DirectCast(formData("BirthDate"), FormTextData)
        birthDateData.Value = New DateTime(2000, 1, 1)

        ' Update "Salary" text box field.
        Dim salaryData As FormTextData = DirectCast(formData("Salary"), FormTextData)
        salaryData.Value = 5432.1

        ' Check "Married" check box field.
        Dim marriedData As FormCheckBoxData = DirectCast(formData("Married"), FormCheckBoxData)
        marriedData.Value = True

        ' Select "Female" from drop down field.
        Dim genderData As FormDropDownData = DirectCast(formData("Gender"), FormDropDownData)
        genderData.SelectedItemIndex = genderData.Items.IndexOf("Female")

        document.Save("Update Form.docx")

    End Sub

End Module

Check next sample.