none
dynamically binding to different custom parts RRS feed

  • Question

  • Hi,
    i have created a template and binded some content controls to a custom xml (let's call it CustomContent.xml).  some of these content controls hold read only data that is populated when a user submits a form to my server.  basically when a user submits a document, i extract the custom xml, and populate ith with data, then add it back to the docx package.  This works great.

    Now the need has come up to allow users to dynamically swap between different sets of data in word.  so what i intend to do is to put each set of data as in the docx (i.e. my docx will have custom parts: CustomContent1.xml, CustomContent2.xml, CustomeContent3.xml, etc - all based on the same schema).  I would like to know how can i now dynamically swap between these custom contents in word?  so for example, if the document is opened and bound to content located in CustomContent1.xml, i'd like to programatically change the bindings to CustomeContent2. 

    Any thoughts?
    Friday, January 22, 2010 5:22 PM

Answers

  • If you look at the SetMapping method you will see that there is a parameter that lets you specify which CustomXMLPart should be used. If you don't specify that, then Word looks at all the CustomXMLparts and just chooses the first "hit". There is no other way.
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bessie Zhao Friday, January 29, 2010 5:45 AM
    Sunday, January 24, 2010 6:44 PM
    Moderator

All replies

  • Hi Mark

    In order to map a content control to a CustomXMLPart, the XMLMapping.SetMapping method is used. So all you need to do is execute that to refer to the CustomXML part and node you want connected to the Content Control.

    You'll have to have something in the Custom XML Part that will let your code identify it. Since I have no idea of the schema or content or what would be different between these Custom XML Parts I can't make any suggestions about that.
    Cindy Meister, VSTO/Word MVP
    Sunday, January 24, 2010 8:45 AM
    Moderator
  • Thanks Cindy. That is not exactly my issue however.  as mentioned earlier, in my case my my .docx package contains two custom parts based on the same schema, however these custom parts actually have different content data.  so no mapping at of content controls should be needed since the schema is the same and thus the xpath will be the same.   What i do need to figure out however is how to tell word to use CustomContent2.xml instead of CustomContent1.xml. 

    I believe the mapping here is in the docx itself (i.e. perhaps mapping document.xml to point to CustomConent1 or CustomContent2 programmatically).  I am not sure how to do this at run time (when the document is open in word).  I understand it might be possible to do this using the OpenSDK, but i also understand that can not be done if the document is opened already - which in this case it will be.

    Sunday, January 24, 2010 3:51 PM
  • If you look at the SetMapping method you will see that there is a parameter that lets you specify which CustomXMLPart should be used. If you don't specify that, then Word looks at all the CustomXMLparts and just chooses the first "hit". There is no other way.
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bessie Zhao Friday, January 29, 2010 5:45 AM
    Sunday, January 24, 2010 6:44 PM
    Moderator