Insert Content Control in Word using C#

This tutorial explains how to insert content control in Word using C#. It includes details on setting up the development environment, step-by-step instructions, and sample code for adding an MS Word content control using C#. You will also learn how to customize the output Word file by changing the characteristics of the SDTs added to the output DOCX Word file.

Steps to Insert a Rich Text Content Control using C#

  1. Configure the application to use Aspose.Words for .NET to add an SDT to a Word file
  2. Create a new Word file using the Document object and add a heading at the top
  3. Add a rich text box with the desired formatting
  4. Lock the rich text control to prevent deletion while allowing editing
  5. Add a plain text box control filled with a sample value
  6. Add a checkbox control that is unchecked by default
  7. Add a drop-down list with a few entries and select one of the values
  8. Add a date picker with today’s date
  9. Save the document with all the SDTs

These steps guide you through working with various SDT controls, including the rich text content control using C#. Create a blank Word file, add a heading, add a rich text content control with formatted text, add an inline plain text content control, and a checkbox. Add more controls, like a drop-down list content control and a date picker content control, before saving the resultant Word file.

Code for Word Content Controls using C#

This code demonstrates the usage of Word document content control using C#. You can also set the appearance, color, style, content font, and multiline flag of each control. Set the placeholder text using PlaceholderName, lock the controls so that users cannot delete them, and use SdtType.RepeatingSection with RepeatingSectionItem for repeating data such as line items instead of inserting several separate controls.

This article teaches the process of inserting a content control in Word. To convert a DOCX to JPG, refer to the article Convert DOCX to JPG using C#.