string docTemplatePath = @"E:m.docx"; string docOutputPath = @"E:mm.docx"; File.Copy(docTemplatePath, docOutputPath); using (WordprocessingDocument doc = WordprocessingDocument.Open(docOutputPath, true)) { string newXml = "<root>"+ "<MatterNumber>00011111</MatterNumber>" + "<DocType>Contract</DocType>" "<root>"; MainDocumentPart main = doc.MainDocumentPart; main.DeleteParts<CustomXmlPart>(main.CustomXmlParts); CustomXmlPart customXml = main.AddCustomXmlPart(CustomXmlPartType.CustomXml); using (StreamWriter ts = new StreamWriter(customXml.GetStream())) { ts.Write(newXml); } } Console.WriteLine("Done"); Console.ReadLine();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)