I am adding some kind of custom XML to docx to track it inside the application that I am writing.
I manually did this by opening a Word document through the ZIP library and through the official Open XML SDK route. Both have the same result as my XML inserted into the customXml folder in the document. The document opens perfectly in Word for both of these methods, and XML is present.
BUT, but when I save the document as MyDoc2.docx, for example, all my XML disappears.
What am I doing wrong?
Microsoft links I'm following:
http://msdn.microsoft.com/en-us/library/bb608597.aspx
http://msdn.microsoft.com/en-us/library/bb608612.aspx
And the code I took from the Open XML SDK 2.0:
public static void AddNewPart(string document, string fileName) { using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true)) { MainDocumentPart mainPart = wordDoc.MainDocumentPart; CustomXmlPart myXmlPart = mainPart.AddCustomXmlPart(CustomXmlPartType.CustomXml); using (FileStream stream = new FileStream(fileName, FileMode.Open)) { myXmlPart.FeedData(stream); } } }
Thanks, John
source share