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.

Update Form Screenshot
Upload your file (Drag file here)
using System;
using GemBox.Document;

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

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

        // 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.%OutputFileType%");
    }
}
Imports System
Imports GemBox.Document

Module Samples

    Sub Main()

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

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

        ' 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.%OutputFileType%")

    End Sub

End Module

Check next example or download examples from GitHub.