代码之家  ›  专栏  ›  技术社区  ›  Perry

下载保存在我的服务器选项上的文件

  •  0
  • Perry  · 技术社区  · 6 年前

    我有这个代码:

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DownLoad")
            {
    
                Response.Clear();
                Response.ContentType = "application/octet-stream";
                Response.AppendHeader("content-disposition", "filename =" + 
               e.CommandArgument);
    
    Response.TransmitFile(Server.MapPath("~/Uploads/")+e.CommandArgument);
                Response.End();
            }
        }
    

    代码可以工作,但它会打开.txt文档和.pdf文档,并在Web浏览器中显示它们。如果我下载了.csv或.doc文件,系统会提示我保存或打开该文件。对于所有下载的文件,我希望有保存或打开选项。

    0 回复  |  直到 6 年前