2017-05-05 60 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(); 
} 
相關問題