【问题标题】:Download File from http handler with custom name使用自定义名称从 http 处理程序下载文件
【发布时间】:2015-02-04 07:36:00
【问题描述】:

我在上传文件夹中有不同的文件,包括 .doc、.docx、.pdf、.xls 等,我想在单击图像时下载文件。我从 jquery 值调用 http 通用处理程序正确传递但不工作

                HttpContext.Current.Response.ClearHeaders();
                HttpContext.Current.Response.ClearContent();
                HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
                HttpContext.Current.Response.AppendHeader("Content-Length", fileInfo.Length.ToString());
                HttpContext.Current.Response.ContentType = "application/octet-stream";
                HttpContext.Current.Response.TransmitFile(fileInfo.FullName);
                HttpContext.Current.Response.Flush();

【问题讨论】:

    标签: jquery httphandler xls


    【解决方案1】:

    试试这样的:

    Response.Clear();
    Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
    Response.AddHeader("Content-Length", fileInfo.Length.ToString());
    Response.ContentType = "application/octet-stream";
    Response.WriteFile(fileInfo.FullName);
    Response.End();
    

    应该可以了!

    【讨论】:

      猜你喜欢
      • 2012-10-25
      • 1970-01-01
      • 1970-01-01
      • 2015-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多