This documentation is archived and is not being maintained.

DocumentBase.SelectLinkedControls Method (CustomXMLNode)


Returns all the content controls in the document that are linked to the specified custom XML node.

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

public ContentControls SelectLinkedControls(
	CustomXMLNode node


Type: Microsoft.Office.Core.CustomXMLNode

The CustomXMLNode to which the content controls are linked.

Return Value

Type: Microsoft.Office.Interop.Word.ContentControls

A ContentControls collection that contains the content controls that are linked to the specified custom XML node.

The following code example adds three plain text content controls to the current document. The example also adds a CustomXMLPart that contains employee data and links two of the content controls to XML nodes in the CustomXMLPart. Next, the code gets the controls that are linked to the employee name node, displays a message box that shows the number of linked controls found, and finally iterates through the linked controls to display the title of each linked control. When you run this code, you should get one linked control and its title should be Employee Name. To use this example, run it from the ThisDocument class in a document-level project.

private void LinkedControls()
    Microsoft.Office.Tools.Word.PlainTextContentControl employeeName = 
    employeeName.Title = "Employee Name";
    Microsoft.Office.Tools.Word.PlainTextContentControl employeeHireDate = 
    employeeHireDate.Title = "Employee Hire Date";
    Microsoft.Office.Tools.Word.PlainTextContentControl comments =
    comments.Title = "Comments";

    string xmlString = 
        "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" 
        + "<employees>" 
        + "<employee>" 
        + "<name>Karina Leal</name>" 
        + "<hireDate>1999-04-01</hireDate>"             
        + "</employee>" 
        + "</employees>";
    Office.CustomXMLPart employeeXMLPart = 
        this.CustomXMLParts.Add(xmlString, missing);

        "/employees/employee/name", "", employeeXMLPart);
        "/employees/employee/hireDate", "", employeeXMLPart);

    Office.CustomXMLNode node = employeeXMLPart.SelectSingleNode(

    Word.ContentControls linkedControls = this.SelectLinkedControls(node);
    MessageBox.Show("Number of controls linked to the " + node.XPath 
                    + " node: " + linkedControls.Count.ToString());
    foreach (Word.ContentControl linkedControl in linkedControls)
        MessageBox.Show("Linked control title: " + linkedControl.Title);
Return to top