0

尝试将文件从服务器下载到客户端时出现问题。单击时,保存文件提示显示为应有的样子,但它不指向我要下载的文件,而是指向我的 aspx 页面?换句话说,它不会下载我想下载的文件,而是下载下载链接所在的页面。真的很奇怪......似乎我指定下载的文件被完全忽略/没有效果......

if (File.Exists(Server.MapPath(driversLocation + name + ".zip")))
{
    FileInfo fileInfo = new FileInfo(Server.MapPath(driversLocation) + name + ".zip");

    Response.Clear();
    Response.AddHeader("Content-Disposition", "inline;attachment; filename=" + name + ".zip");
    Response.AddHeader("Content-Length", fileInfo.Length.ToString());
    Response.ContentType = "application/download";
    Response.Flush();
    Response.TransmitFile(Server.MapPath(driversLocation) + name + ".zip");
    Response.End();
 }

任何帮助,将不胜感激!

4

1 回答 1

0

问题是“内联”。还有一些其他的事情需要调整以使代码更易于阅读:

相关文章:Content-Disposition:“内联”和“附件”有什么区别?

FileInfo fileInfo = new FileInfo(Server.MapPath(driversLocation + name + ".zip"));

if (fileInfo.Exists)
{
     Response.Clear();
     Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
     Response.AddHeader("Content-Length", fileInfo.Length.ToString());
     Response.ContentType = "application/x-zip-compressed";
     Response.TransmitFile(fileInfo.FullName);
     Response.End();
}
于 2012-11-23T15:31:59.563 回答