【问题标题】:Can not download file from project directory (asp.net)无法从项目目录(asp.net)下载文件
【发布时间】:2016-12-06 16:37:15
【问题描述】:

这是我的问题。我正在尝试从 asp.net 项目目录下载文件。文件位于“日期”目录中。我已经使用 GridView 完成了 WebForm1.aspx 页面,该页面在 Date 目录中显示文件。所有文件都像链接一样显示。
底部有我的代码。

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if(e.CommandName == "Download")
    {
        Response.Clear();
        Response.ContentType = "text/plain";
        Response.AppendHeader("content-disposition", "filename" + e.CommandArgument);
        Response.TransmitFile(Server.MapPath("~/Data/") + e.CommandArgument);            
        Response.End();
    }
}

我通过文件的链接。之后,我的浏览器提供的不是下载我的文件,而是所有页面的文件(WebForm1.aspx) 帮我解决这个问题。我做错了什么?

image with problem

【问题讨论】:

    标签: c# asp.net file download server


    【解决方案1】:

    您的处置标题不正确(没有attachment,缺少=),更改为:

    Response.AppendHeader("content-disposition", "attachment; filename=" + e.CommandArgument);
    

    【讨论】:

      猜你喜欢
      • 2016-05-23
      • 1970-01-01
      • 2017-05-16
      • 1970-01-01
      • 1970-01-01
      • 2011-01-01
      • 2017-07-29
      • 1970-01-01
      • 2012-02-15
      相关资源
      最近更新 更多