views:

40

answers:

1

I need to attach specific XML to a word document so the elements will show up in the right places. This I can do with OpenXML SDK.

The thing is I want too be able to define the Content Controls already bounded in some sort of template so other people can create the real document template the xml will be attached to. Ok not sure people will undestand what I mean so I will explain further.

There may be many different document templates that will use the same XML data and so the same Content Controls. It's up to someone else to create the document.

Scenario: Some dude that's not a programmer needs to create a new form for the usual info because of some changes ( new layout or somehting ). This has nothing to do with the XML info, that stays the same.

Optimal solution for "some dude" would be to create the document in Word and drag the Content Controls into place ( or some solution similiar). Then when the XML gets added to the document there is no problem as the Content Controls are pre-binded.

Now there are a few points here:

1) Can Content Controls be pre-binded? If there is no XML at the path won't it just stay empty without problems?

2) Will binding Content Controls to CustomXML's like this still work in future versions of Word because of the i4i lawsuit?

3) Is there perhaps another optimal solution better then this?

Thanks in advance.

EDIT:

To be more clear. I wan't to create Content Controls that would have some name to identify them and a databound xpath. However at that moment there is nothing at the path.

Another user comes in and creates a form, decides the layout on so on, and then adds the Content Controls into the places he wants the info to be.

Later on the info for item X is requested using the new form. So a copy of that form will be taken and the CustomXML will be added into the Docx file. Now because the XML shchema was known beforehand and used when deciding the paths for the CC's this XML data will be bound to the Content Controls.

+1  A: 

One great option would be to use VSTO (Visual Studio for Office) to build a set of document templates that have your prebinding code attached. These two articles provide a good start into looking into this type of a solution:

There are two threads that discuss some details of this: 1 and 2.

One of the benefits about using VSTO is that you can hook the Content Control events: Content Control Event Model in Word 2007.

If VSTO is not an option, you can always look at Add Custom XML Parts to Documents Without Starting Microsoft Office.

Otaku
I currently don't have VSTO, think I need professional version of VS for it. But maybe I'll grab one. Haven't looked at the other article but I do know how to attach the CustomXML just don't like most solutions of binding after adding cause I can't trust the Document makers to add the CC's right. Will check this out and then let you know and give right answer if all good.
Ingó Vals
Cool. I've added one more set of links on VSTO's CC events. That may be helpful to hook user insertion of CCs and validate.
Otaku
BTW - the general practice is not to have end users insert CCs. Rather, they insert Building Blocks (which can contain CCs) - Insert>QuickParts. That way you don't have them mucking with the dev tool bar.
Otaku