日期:2014-05-17 浏览次数:20480 次
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>