/// <summary> /// Binds content controls to a custom XML part created or updated from the given XML document. /// </summary> /// <param name="document">The WordprocessingDocument.</param> /// <param name="rootElement">The custom XML part's root element.</param> public static void BindContentControls(this WordprocessingDocument document, XElement rootElement) { if (document == null) { throw new ArgumentNullException("document"); } if (rootElement == null) { throw new ArgumentNullException("rootElement"); } // Get or create custom XML part. This assumes that we only have a single custom // XML part for any given namespace. var destPart = document.GetCustomXmlPart(rootElement.Name.Namespace); if (destPart == null) { destPart = document.CreateCustomXmlPart(rootElement); } else { destPart.SetRootElement(rootElement); } // Bind the content controls to the destination part's XML document. document.BindContentControls(destPart); }