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.
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);
}
}
}
Create and fill out forms with legacy form fields such as text, dropdown, and checkbox fields. Then, seamlessly extract the filled data from them.
Enhance your forms by incorporating content controls such as plain text, rich text, pictures, checkboxes, combo boxes, dropdown lists, and date pickers.
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.
Bind content controls to an element in a custom XML part embedded in a document.
Discover resources in our knowledge base to enhance your efficiency in form filling in Word documents:
Knowledge base
Knowledge base
Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.
Product Updates
Technical Support
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.
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.