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 shows how you can write or modify values of an existing text, check-box and drop-down form fields in a document.

Updating Word document's text, check-box and drop-down form fields in C# and VB.NET
Screenshot of Word file with updated form field values
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.

        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.

        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

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.

Like it?

Download Buy

If you want to try the GemBox.Document yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.