DocumentBase.SelectContentControlsByTag Method (String)


Returns all the content controls in the document that have the specified tag.

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

public ContentControls SelectContentControlsByTag(
	string tag


Type: System.String

The tag of the content controls to return.

Return Value

Type: Microsoft.Office.Interop.Word.ContentControls

A ContentControls collection that contains the content controls that have the specified tag.

The following code example adds three paragraphs to the document and then adds one control to each new paragraph: a RichTextContentControl, a ComboBoxContentControl, and a DropDownListContentControl. The example sets the Tag and Title properties of each control. Next, the code calls the SelectContentControlsByTag method to get the collection of native content controls whose tag value equals Customer and then displays the title of each control from the returned collection in a message box. To use this example, run it from the ThisDocument class in a document-level project.

private void ContentControlsTag()
    Word.Paragraph par1 = this.Paragraphs.Add(ref missing);
    Microsoft.Office.Tools.Word.RichTextContentControl richTextControl =
    richTextControl.Tag = "Customer";
    richTextControl.Title = "Customer Name";

    Word.Paragraph par2 = this.Paragraphs.Add(ref missing);
    Microsoft.Office.Tools.Word.ComboBoxContentControl comboBoxControl =
    comboBoxControl.Tag = "Customer";
    comboBoxControl.Title = "Customer Title";

    Word.Paragraph par3 = this.Paragraphs.Add(ref missing);
        dropDownListControl = this.Controls.AddDropDownListContentControl(
        par3.Range, "dropDownListControl");
    dropDownListControl.Tag = "Products";
    dropDownListControl.Title = "List of Products";

    Word.ContentControls relatedControls = 
    MessageBox.Show("Displaying all controls with a Tag value of" + 
        " 'Customer'. Click OK to continue.");
    foreach (Word.ContentControl ctrl in relatedControls)
        MessageBox.Show("Control title: " + ctrl.Title);
Return to top