combine docx file

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

Hi,

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
                    .Parts
                    .Select(p => p.OpenXmlPart)
                    .Where(p => p.ContentType == "application/vnd.openxmlformats-officedocument.customXmlProperties+xml")
                    .First();

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(
                mainPart.DeleteParts<CustomXmlPart>(mainPart.CustomXmlParts);
                //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);
            }

Thanks,