Expand Minimize

DocumentBase.ContentControls Property

Gets the collection of all the content controls in the document.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

public ContentControls ContentControls { get; }

Property Value

Type: Microsoft.Office.Interop.Word.ContentControls
A ContentControls collection that contains all the content controls in the document.

This property returns the collection of native content controls in the document (that is, the Microsoft.Office.Interop.Word.ContentControl objects in the document).

To access the extended content controls in the document, use the Controls property.

For more information about extended content controls, see Content Controls.

The following code example adds a plain text control to the first paragraph and sets the control title. The code then iterates through all content controls in the document and shows a message box that displays the type and title of each content control. To use this example, run it from the ThisDocument class in a document-level project.

private void IterateContentControls()
    object _range = this.Paragraphs[1].Range;
    Word.ContentControl textControl1 = this.ContentControls.Add(
            ref _range);
    textControl1.Title = "First Name";

    foreach (Word.ContentControl cc in this.ContentControls)
        MessageBox.Show("Content control  type: " 
            + cc.Type.ToString() + ", title: " + cc.Title);

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft