2017-05-05 177 views
2

我打电话这种直接的方法,但是当我尝试下载文件(路径是确定和测试),我收到此错误:C#下载文件 - BADRESPONSE:无效的或意外的标记

[DirectMethod] 
    public void downloadFile(string fname, string ftype) 
    { 
     HttpContext.Current.Response.ContentType = "APPLICATION/OCTET-STREAM"; 
     String Header = "Attachment; Filename=" + fname; 
     HttpContext.Current.Response.AppendHeader("Content-Disposition", Header); 
     System.IO.FileInfo Dfile = new System.IO.FileInfo(HttpContext.Current.Server.MapPath("CopyFiles\\" + ftype + "\\"+ fname)); 
     HttpContext.Current.Response.WriteFile(Dfile.FullName); 
     HttpContext.Current.Response.End(); 
    } 

BADRESPONSE:无效的或意外的标记

回答

0

它只是需要刷新()的WriteFile()之前:

[DirectMethod] 
public void downloadFile(string fname, string ftype) 
{ 
    HttpContext.Current.Response.ContentType = "APPLICATION/OCTET-STREAM"; 
    String Header = "Attachment; Filename=" + fname; 
    HttpContext.Current.Response.AppendHeader("Content-Disposition", Header); 
    System.IO.FileInfo Dfile = new System.IO.FileInfo(HttpContext.Current.Server.MapPath("CopyFiles\\" + ftype + "\\"+ fname)); 
    HttpContext.Current.Response.Flush(); 
    HttpContext.Current.Response.WriteFile(Dfile.FullName); 
    HttpContext.Current.Response.End(); 
} 
相关问题