Open Specifications Developer Center >
Open Specifications Forums
>
Using the Office Protocols
>
How to create a new Office Doc
How to create a new Office Doc
- I'm beating my head against the wall thinking "This CANNOT be that hard", but I can't find the answer.
I am just getting started with the OpenXml SDK, and I have what should be a simple task: I want to read in a Word Template file (.dotx), perform some manipulations on the content, and write it back out as a new Word document (.docx), with a different file name. Disregard the manipulations for the moment. How do I save the package as a new filename? All the examples read in a file, perform manipulations,and use XmlDocument.Save to write it back out, but I can't find a way to change the file name that it's written to. The TargetPath and TargetName properties of the MainDocumentPart are read only, so I can't just change those.
I appreciate the help.
Answers
- Dave,
I didn't see a reply on this so I thought I would toss out some info. The first thing you should know is that this forum is intended for the Open Specifications found here: http://msdn2.microsoft.com/en-us/library/cc203350.aspx. For OpenXML I would ask in one of the standard .NET development forums.
However I did some research on this. You are correct that the TargetName and other properties are read-only and generated at the time the OpenXMLPart is opened. However rather than using actual file names I would use a stream instead. I would leave the stream attached to the OpenXML document but change where the stream points to when you do a save. Check out here: http://msdn.microsoft.com/en-us/library/documentformat.openxml.packaging.wordprocessingdocument.open(office.14).aspx
WordprocessingDocument.Open Method (DocumentFormat.OpenXml.Packaging)
Overload List Name Description WordprocessingDocument.Open (Package) Create a new instance of the WordprocessingDocument class from the spcified package.WordprocessingDocument.Open (Stream, Boolean) Create a new instance of the WordprocessingDocument class from the IO stream.WordprocessingDocument.Open (String, Boolean) Create a new instance of the WordprocessingDocument class from the specified file.
I hope this helps.
Steve Smegner
Application Development Consulting Group- Proposed As Answer bySteve Smegner Wednesday, November 05, 2008 9:51 PM
- Marked As Answer byChris MullaneyMSFT, OwnerThursday, November 20, 2008 5:35 PM
All Replies
Good afternoon Dave. I have alerted our Protocols Support team concerning your questions about [#] One of our team members will be in contact with you soon.
Thanks for your questions!
Regards,
Bill Wesse
Escalation Engineer- Dave,
I didn't see a reply on this so I thought I would toss out some info. The first thing you should know is that this forum is intended for the Open Specifications found here: http://msdn2.microsoft.com/en-us/library/cc203350.aspx. For OpenXML I would ask in one of the standard .NET development forums.
However I did some research on this. You are correct that the TargetName and other properties are read-only and generated at the time the OpenXMLPart is opened. However rather than using actual file names I would use a stream instead. I would leave the stream attached to the OpenXML document but change where the stream points to when you do a save. Check out here: http://msdn.microsoft.com/en-us/library/documentformat.openxml.packaging.wordprocessingdocument.open(office.14).aspx
WordprocessingDocument.Open Method (DocumentFormat.OpenXml.Packaging)
Overload List Name Description WordprocessingDocument.Open (Package) Create a new instance of the WordprocessingDocument class from the spcified package.WordprocessingDocument.Open (Stream, Boolean) Create a new instance of the WordprocessingDocument class from the IO stream.WordprocessingDocument.Open (String, Boolean) Create a new instance of the WordprocessingDocument class from the specified file.
I hope this helps.
Steve Smegner
Application Development Consulting Group- Proposed As Answer bySteve Smegner Wednesday, November 05, 2008 9:51 PM
- Marked As Answer byChris MullaneyMSFT, OwnerThursday, November 20, 2008 5:35 PM


