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()));
这导致损坏的xml文件。字符串如下所示:
"\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
我错过了一些明显的东西吗?我需要手动删除\r\n
吗?感谢
答案 0 :(得分:0)
你不应该序列化字符串。
相反,您应该通过调用doc.Save(response.Output)
直接写入HTTP响应。