Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过Response.TransmitFile导出的Xml中缺少结束标记_C#_Asp.net_Xml_Asp.net Mvc_Asp.net Web Api - Fatal编程技术网

C# 通过Response.TransmitFile导出的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

我正在使用以下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文件的结束标记已损坏。这意味着有些词是含混不清的


有人能告诉我这是什么原因吗

它适用于此代码:

 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();                
            }