HttpContext.Current.Response.ContentType = "text/xml";
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpPostedFile file = HttpContext.Current.Request.Files[0];
XDocument doc = XDocument.Load(XmlReader.Create(file.InputStream));
var wr = new StringWriter();
doc.Save(wr);
HttpContext.Current.Response.Write(serializer.Serialize(wr.GetStringBuilder().ToString()));
This is resulting in a corrupt xml file. The string looks like this:
"\u003c?xml version=\"1.0\" encoding=\"utf-16\"?\u003e\r\n\u003cAuditSheet\u003e\r\n \u003cPLANT_SITE_CUSTOMER_NAME\u003eZINIFEX HOBART SMELTER\u003c/PLANT_SITE_CUSTOMER_NAME\u003e\r\n
Did i miss something obvious here? Do i need to remove the \r\n manually? Thanks
You shouldn’t be serializing the string.
Instead, you should write directly to the HTTP response by calling
doc.Save(response.Output).