I have been using OOXML api to update the custom xml part in a .docx. The code updates the custom xml part in the document. My problem is that the same code replaces and generates perfect .docx when I use in a console App, but it doesn't replaces nor generates .docx when used in ASP.NET application. The code snippet in question is as follows:
string tmp = string.Format("{0}.docx", Guid.NewGuid());
File.Copy(FileName, tmp);
_xml = ReadXML(XmlPath);
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(tmp, true)) {
var mainPart = wordDoc.MainDocumentPart;
mainPart.DeleteParts<CustomXmlPart>(mainPart.CustomXmlParts);
//Add a new customXML part and then add content
var customXmlPart = mainPart.AddCustomXmlPart(CustomXmlPartType.CustomXml);
//copy the XML into the new part...
using (var ts = new StreamWriter(customXmlPart.GetStream())) {
ts.Write(_xml);
ts.Flush();
}
}
I am at square why is this happening. Any help is appreciated Thanks