2012-02-26 15 views
0
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ファイルが壊れています。文字列は次のようになります。ジェネリックハンドラの応答に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

文字列をシリアル化するべきではありません。

代わりに、doc.Save(response.Output)を呼び出してHTTP応答に直接書き込む必要があります。

+0

よろしくお願いします。 JSONのシリアル化から多くのペーストをコピーするには:-)お返事ありがとう – Johan

関連する問題