2013-06-04 127 views
0

我试着下载使用通过我的处理程序和jQuery流的文件,我有一个返回流下载文件

public void ProcessRequest(HttpContext context){ 

    string name = "MyFile.xlsx"   

    context.Response.ContentType = "application/octet-stream"; 
    context.Response.AddHeader("Content-Disposition", "attachment; filename=" + name); 
    Stream stream = GetFileStream("id001"); 

    context.Response.Write (stream); 
} 

以及处理该页面的处理程序处理程序,但我无法映射的回应

function downloadFile(e) { 
     var baseUrl = "./handlers/DownloadReport.ashx?"; 
     e.preventDefault();    
     var dataItem = this.dataItem($(e.currentTarget).closest("tr")); 

     var key = "key=" + dataItem.Link; 
     var name = "&name=" + dataItem.ReportName; 
     $.get(baseUrl + key + name, function (result) { 
      // Check for errors 

     }); 
    } 

任何想法如何使这项工作?

谢谢!

回答

0

我认为问题是,jQuery要么没有得到流EOF,要么当流完成时关闭连接,因此JavaScript无法处理它。

你可以尝试获取与jQuery的流插件流,也许可以帮助: https://code.google.com/p/jquery-stream/wiki/API