Syncfusion Feedback

Trusted by the world’s leading companies

Syncfusion Trusted Companies

Overview

The Syncfusion .NET Word Library (DocIO) enables the creation of fillable forms with both legacy form fields and content controls in C# without relying on Microsoft Word or interop dependencies. It lets users design forms consisting of multiple elements such as plain text, rich text, pictures, checkboxes, combo boxes, and dropdown lists.

Fill a form in a Word document using C#

This sample code shows how to fill a form in a Word document using the Syncfusion .NET Word Library with just few lines of code in C#.

using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using (FileStream inputDocumentStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
    //Creates a new Word document.
    using (WordDocument document = new WordDocument(inputDocumentStream, FormatType.Docx))
    {
        //Find drop-down content control by title.
        InlineContentControl inlineContentControl = document.FindItemByProperty(EntityType.InlineContentControl, "ContentControlProperties.Title", "Status") as InlineContentControl;
        WTextRange textRange = inlineContentControl.ParagraphItems[0] as WTextRange;
        //Select drop-down
        textRange.Text = inlineContentControl.ContentControlProperties.ContentControlListItems[1].DisplayText;
        //Find date content control by tag.
        inlineContentControl = document.FindItemByProperty(EntityType.InlineContentControl, "ContentControlProperties.Tag", "Date") as InlineContentControl;
        textRange = inlineContentControl.ParagraphItems[0] as WTextRange;
        //Set today's date to display.
        textRange.Text = DateTime.Now.ToShortDateString();
        //Find text content control by title.
        inlineContentControl = document.FindItemByProperty(EntityType.InlineContentControl, "ContentControlProperties.Title", "ProjectName") as InlineContentControl;
        //Fill text.
        textRange = inlineContentControl.ParagraphItems[0] as WTextRange;
        textRange.Text = "Website for Adventure works cycle";
        //Find checkbox content control by type.
        inlineContentControl = document.FindItemByProperty(EntityType.InlineContentControl, "ContentControlProperties.Type", "CheckBox") as InlineContentControl;
        //Check the checkbox
        inlineContentControl.ContentControlProperties.IsChecked = true;
        //Creates file stream.
        using (FileStream outputDocumentStream = new FileStream("Result.docx", FileMode.Create, FileAccess.ReadWrite))
        {
            //Saves the Word document to file stream.
            document.Save(outputDocumentStream, FormatType.Docx);
        }
    }
}

Key features of form filling

Legacy form fields

Create and fill out forms with legacy form fields such as text, dropdown, and checkbox fields. Then, seamlessly extract the filled data from them.

Content controls

Enhance your forms by incorporating content controls such as plain text, rich text, pictures, checkboxes, combo boxes, dropdown lists, and date pickers.

Restrict editing

Protect the content of content controls from being edited by locking their content. You can also prevent a content control from being deleted from the document.

Binding

Bind content controls to an element in a custom XML part embedded in a document.

Form-filling references

Discover resources in our knowledge base to enhance your efficiency in form filling in Word documents:

Removing a content control without deleting content

Knowledge base

How to remove a content control without deleting content in a Word document using C#

Removing placeholder text if the meta property is empty

Knowledge base

How to remove placeholder text if the meta property is empty in a Word document

Syncfusion .NET Word Library Resources

Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.

Frequently Asked Questions

No, you can identify the content controls based on their title or tag using the find functionality in the .NET Word Library.

Yes, you can customize the properties of content controls in a Word document using the .NET Word Library.

Yes, you can lock content controls to restrict editing or deletion.

It’s preferable to use content controls to design forms.

Yes, the .NET Word Library enables exporting legacy form fields as editable elements in a PDF when converting a Word file to a PDF.

You can access it through the Syncfusion.DocIO.Net.Core NuGet package. Detailed code samples and tutorial video are available in the documentation.

Our Customers Love Us

Having an excellent set of tools and a great support team, Syncfusion® reduces customers’ development time.
Here are some of their experiences.

Rated by users across the globe

Want to create, View, and edit Word documents in C# or VB.NET?

Start a free 30-day evaluation today!
DOWNLOAD FREE TRIAL

No credit card required.

Mobile Free Evaluation Section

Awards

Greatness—it’s one thing to say you have it, but it means more when others recognize it. Syncfusion® is proud to hold the following industry awards.

Scroll up icon