【问题标题】:How can I automatically prompt a file download in asp.net?如何在asp.net中自动提示文件下载?
【发布时间】:2011-08-12 07:49:25
【问题描述】:

我在 asp.net 中的应用程序使用 vb.net 脚本生成一个带有系统处理输出的文件,响应按钮单击。该文件存储在服务器的一个文件夹中,我想为用户自动开始下载该文件。我该怎么做?

【问题讨论】:

    标签: vb.net asp.net-ajax


    【解决方案1】:

    以下代码将向用户显示标准的“另存为..”对话框。您需要将内容类型更改为文件的 mime。

    Response.ContentType = "image/jpeg";
    Response.AppendHeader("Content-Disposition","attachment; filename=yourfile.jpg");
    Response.TransmitFile( Server.MapPath("~/yourfile.jpg") );
    Response.End();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-22
      • 1970-01-01
      • 2018-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-07
      • 1970-01-01
      相关资源
      最近更新 更多