我正在使用以下C#asp.net代码导出XML文件
var myfile = new FileInfo(filePath);
if (myfile.Exists)
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);
HttpContext.Current.Response.AddHeader("Content-Length", myfile.Length.ToString());
HttpContext.Current.Response.ContentType = "text/xml";
HttpContext.Current.Response.TransmitFile(myfile.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
HttpContext.Current.Response.End();
}
导出已成功完成,但是当我查看导出的xml文件时,xml文件的结束标记已损坏。这意味着有些词语正在消失。
谁能告诉我这是什么原因?
答案 0 :(得分:0)
它适用于此代码:
var myfile = new FileInfo(filePath);
if (myfile.Exists)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);
HttpContext.Current.Response.AddHeader("Content-Length", myfile.Length.ToString());
HttpContext.Current.Response.ContentType = "text/xml";
HttpContext.Current.Response.TransmitFile(myfile.FullName);
HttpContext.Current.Response.End();
}