<a>超链接实现下载,普通文件只是打开,特殊后缀的文件无法下载,怎么能让所有的文件都是呈下载,不用打开
<a>超链接实现下载,普通文件只是打开,压缩文件是可以下载,特殊后缀的文件无法下载(注册表注册过后缀的文件能够打开或右键下载),,,,怎么能让所有的文件都是呈下载,不用打开???????
我后台写了个方法
public void ResponseFile(string path)
{
string fileName = HttpContext.Current.Server.UrlEncode(path.Substring(path.LastIndexOf("/") + 1));
try
{
FileInfo info = new FileInfo(HttpContext.Current.Server.MapPath(path));
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
//不指明Content-Length用Flush的话不会显示下载进度
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(path, 0, fileSize);
Response.Flush();
Response.Close();
}
catch (Exception ex)
{
Response.Write("无法下载文件:" + fileName + ",由于:" + ex.Message + "");
}
}
]<a href="#" onclick="<%=ResponseFile(" + path + ")%)">" + dr[0].ToString() + "</a>