Update Word Form Controls in C# and VB.NET

Besides reading a form you can also write or update the form field values. This is done by using the FormTextData.Value, FormCheckBoxData.Value or FormDropDownData.SelectedItemIndex property.

When setting the FormText field's value to an IFormattable type (like a number or date), the field's resulting text will depend on the value of FormTextData.ValueFormat.

The following example demonstrates how you can write or modify values of an existing text, check-box and drop-down form fields in a document.

Screenshot of Word file with updated form field values
Updating Word document's text, check-box and drop-down form fields in C# and VB.NET
Upload your file (Drag file here)
using System;
using GemBox.Document;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var document = DocumentModel.Load("%InputFileName%");

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

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

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

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

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

        document.Save("Form Updated.%OutputFileType%");
    }
}
Imports System
Imports GemBox.Document

Module Program

    Sub Main()

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

        Dim document = DocumentModel.Load("%InputFileName%")

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

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

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

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

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

        document.Save("Form Updated.%OutputFileType%")

    End Sub
End Module

Check next example or download examples from GitHub.