How to: Bind Controls to a Specific Row in the Data Store When Inserting a Building Block
Word Developer Reference |
A document building block is a predesigned piece of content, such as a cover page, a header, a footer, or a custom-built clause in a contract. Custom building blocks make it easier for you to quickly create professional-looking Microsoft Office Word 2007 documents.
You can use content controls within custom building blocks that have been mapped to XML that contains data. The contents of those content controls are then automatically linked to the appropriate custom XML part (if present) when the part is inserted. Alternatively, as the following sample shows, you can dynamically add the custom XML part and the XML mappings when the part is inserted. For example, to construct a cover page, you can place a picture content control that displays an image retrieved from an element in an attached CustomXMLPart object. Similarly, you can create the project name using a text content control that you map to an element in a CustomXMLPart object containing the project name.
This makes it easier to update your data. To update one of these items, you can write a few lines of code to update every document stored on the server that uses this cover page building block. For example, you can replace an old logo with a new one. Or, if the project title changes, you can update the text in the XML element that you mapped to the text content control containing the project name, thereby automatically updating all the documents stored on the server.
The objects used in these samples are:
- ContentControl
- ContentControls
- CustomXMLPart (2007 Microsoft Office system core object model)
- CustomXMLParts (2007 Microsoft Office system core object model)
- XMLMapping
Sample
Suppose the user has inserted your custom document building block into a document, and based on that action, you want to insert and map to the custom XML part.
|
The following sample code loads the previous XML file and maps each content control to the appropriate XML node in that new custom XML part, when the document building block called "Company Report" is added.
|