combine docx file

Topics: User Forum
Dec 17, 2011 at 7:34 AM


I'm using OpenXML to create docx file, and use Word Context Control Toolkit, it's ok.

But, I generated 200 docx file and want to combine its together, i try using DocumentBuilder, and it raise erorr at function CopyCustomXml

OpenXmlPart propertyPart = customXmlPart
                    .Select(p => p.OpenXmlPart)
                    .Where(p => p.ContentType == "application/vnd.openxmlformats-officedocument.customXmlProperties+xml")

Here is my code

 using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileName, true))
                MainDocumentPart mainPart = wordDoc.MainDocumentPart;
               // string content = "application/vnd.openxmlformats-officedocument.customXmlProperties+xml";
               // mainPart.DeletePart(
                //Add a new customXML part and then add the content.
                CustomXmlPart customXmlPart = mainPart.AddCustomXmlPart(CustomXmlPartType.CustomXml);
                // customXmlPart = mainPart.AddCustomXmlPart(content);
                //Copy the XML into the new part.
                using (StreamWriter ts = new StreamWriter(customXmlPart.GetStream())) ts.Write(customXML);