首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎样点击下载文件而不是直接打开解决办法

2012-05-31 
怎样点击下载文件而不是直接打开a href%#Eval(path) % target_blank下载/a点击下载后是浏览

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

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

C# code
        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(); 

热点排行