Microsoft InfoPath 2010
The official blog of the Microsoft InfoPath team

Data binding between Document Information Panel and Word document

Data binding between Document Information Panel and Word document

Rate This
  • Comments 8
The Document Information Panel is a Microsoft Office InfoPath 2007 form that is hosted and displayed in a Microsoft Office Word 2007, Microsoft Office Excel 2007 or Microsoft Office PowerPoint 2007 document. It enables users to view and edit properties of a document or a content type that is associated to a document management server.
In Microsoft Office Word 2007, users can add properties from Document Information Panel as content controls to document surface. This is also known as data binding between Document Information Panel and Word document. Users can bind Document Properties, Server Content Type Properties or Custom Properties. Once the data is successfully bound, users can edit the properties from Word document surface.
This article will demonstrate two ways to bind data from Document Information Panels to Word document surface.
Method 1: Binding Document Properties or Server Content Type Properties to document surface
  1. Launch Office Word 2007
  2. File | Open to open any Document Information Panel document
  3. Place IP in the document where you want the property control to be
  4. Click Ribbon UI Insert | Quick Parts | Document Property
  5. Choose the property you want to add:

You now have a content control in Word surface that binds data to Document Information Panel property. Please note that this method also works for Server Properties, but you need to save or associate the document with the Server document library first. Then you will see Server Properties in Quick Parts | Document Property list.
 
Method 2: Binding Custom Properties to document surface
For non-document or non-server related properties, which are defined as Custom Properties in this blog, there is no UI to bind these properties directly to document surface. Users need to use Word Object Model to do the data binding.
Assume the Custom Document Information Panel has the following data structure:
Here are the steps to bind the costCenterID property to Word document.
  1. Launch Microsoft Word 2007
  2. File | Open to open a document that contains this custom Document Information Panel
  3. Press Alt+F11 to launch Microsoft Visual Basic editor
  4. Press Ctrl+G to launch the Immediate window
  5. In the Immediate window, add a Text content control by triggering the following command:
ActiveDocument.ContentControls.Add wdContentControlText
  1. Set up this content control XML mapping to costCenterID node by triggering the following command:
ActiveDocument.ContentControls(1).XMLMapping.SetMapping "//*[local-name(.)='costCenterID']",, ActiveDocument.CustomXMLParts(4)
Here the SetMapping function takes three arguments. First input is the XPath of the node you plan to do a mapping.  Second one is PrefixMapping input. Last one is Custom XML Part source where the node belongs to. In this case, costCenterID node lives in 4th custom XML part.
  1. Switch back to Word active document window. The content control should get set up.

Now you have successfully set up properties mapping between Document Information Panel and Word document. When you edit the properties from Word document, the value is updated in the Document Information Panel automatically or vice versa.
If you'd like to know more about the Document Information Panel, be sure to check out this webcast.
Emily Ching
Software Design Engineer in Test
Leave a Comment
  • Please add 8 and 7 and type the answer here:
  • Post
Page 1 of 1 (8 items)