C# 通过Response.TransmitFile导出的Xml中缺少结束标记
我正在使用以下C asp.net代码导出XML文件C# 通过Response.TransmitFile导出的Xml中缺少结束标记,c#,asp.net,xml,asp.net-mvc,asp.net-web-api,C#,Asp.net,Xml,Asp.net Mvc,Asp.net Web Api,我正在使用以下C asp.net代码导出XML文件 var myfile = new FileInfo(filePath); if (myfile.Exists) { HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.AddHeader("Content-Disposition", "at
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文件的结束标记已损坏。这意味着有些词是含混不清的
有人能告诉我这是什么原因吗 它适用于此代码:
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();
}