2017-05-05 3 views
2

私はこの直接メソッドを呼び出していますが、私は、ファイルをダウンロードしようとすると、私は(パスがOKとテストである)、このエラーが表示されます。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(); 
} 
関連する問題