<a href="<%#Eval("path") %>" target="_blank">下载</a>  点击下载后是浏览器直接打开文件,怎么弄成下载文件

解决方案 »

  1.   

    默认情况下你的href,如果是浏览器识别的MIME类型,它会打开,如果不识别的就会显示下载,当然也和客户端设置有关系。
      

  2.   

    试试:
            string filePath = Server.MapPath("~/yourCatalog/yourFile.xxx");
            FileStream fs = new FileStream(filePath, FileMode.Open);
            byte[] bytes = new byte[(int)fs.Length];
            fs.Read(bytes, 0, bytes.Length);
            fs.Close();
            Response.ContentType = "application/octet-stream";//通知浏览器下载文件而不是打开
            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("yourFile.xxx", System.Text.Encoding.UTF8));
            Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End();
      

  3.   

    取决于浏览器关联的mine类型
    一旦关联,一般浏览格式的都是直接打开 如文本,图片.
    一些则不会打开,如 rar压缩文件,exe可执行文件还有没有关联,或者无法关联的文件都会提示下载