This tutorial explains how to insert a content control in Word using C#. Include details on how to set up the development environment, step-by-step instructions, and sample code to add an MS Word content control using C#. You will also learn how to customize the output Word file by modifying the characteristics of the SDTs added to the output Word file DOCX.
Steps to insert a formatted text content control using C#.
- Configura l’applicazione per utilizzare Aspose.Words for .NET per aggiungere un SDT a un file Word
- Create a new Word file using the Document object and add a header at the top.
- Add a text box with the desired formatting.
- Block the rich text control to prevent deletion while allowing editing.
- Add a simple text box control filled with a sample value.
- Add an unchecked checkbox control by default.
- Add a dropdown list with some items and select one of the values.
- Add a date picker with today’s date.
- Salva il documento con tutti gli SDTs
These steps guide you in using various SDT controls, including the rich text content control with C#. Create an empty Word file, add a header, add a rich text content control with formatted text, add an inline plain text content control, and a checkbox. Add more controls, such as a dropdown list content control and a date picker content control, before saving the resulting Word file.
Code for Word content controls using C#
This code demonstrates the use of Word document content control with C#. It is also possible to set the appearance, color, style, content font, and the 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 repeated data such as the rows of a list instead of inserting multiple separate controls.
This article explains the process of inserting a content control in Word. To convert a DOCX to JPG, see the article Convert DOCX to JPG using C#.