tags:

views:

815

answers:

1

I have a bit of code that will open a Word 2007 (docx) document and update the appropriate CustomXmlPart (thus updating the Content Controls in the document itself as they are mapped to the CustomXmlPart) but can't work out how to save this as a new file.! Surely it can't be that hard!

My current thinking is that I need to open the template and copy the content into a new, blank document - file by file, updating the CustomXmlPart when I encounter it. Call me old fashioned but that sounds a little bit clunky to me!

Why can't I just do a WordprocessingDocument.SaveAs(filename); ...?

Please tell me I am missing something simple here.

Thanks in advance

+2  A: 

Are you referring to the OpenXml SDK? Unfortunately, as of OpenXml SDK 2.0, there's no SaveAs method. You'll need to:

  1. Make a temporary copy of your template file, naming it whatever you want.
  2. Perform your OpenXml changes on the above file.
  3. Save the appropriate sections (ie. using the .myWordDocument.MainDocumentPart.Document.Save() method for the main content or someHeaderPart.Header.Save() method for a particular header).
Ahmad Mageed
That's pretty much what I ended up doing - seems a bit of an omission to me. If you open a document and modify it then it stands to reason that you might want to save the updated version with a different name.
DilbertDave