文件下载不要直接指向文件本身
private void DownBackup(string fileName, string zipPath)
{
string path = Server.MapPath(zipPath);
FileInfo file = new System.IO.FileInfo(@path);
Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName) + ".zip");
Response.AppendHeader("Content-Length", file.Length.ToString());
Response.Charset = "gb2312";
string fileExtension = file.Extension;
// 根据文件后缀指定文件的Mime类型
switch (fileExtension)
{
case ".mp3":
Response.ContentType = "audio/mpeg3";
break;
case "mpeg":
Response.ContentType = "video/mpeg";
break;
case "jpg":
Response.ContentType = "image/jpeg";
break;
case "........等等":
Response.ContentType = "....";
break;
default:
Response.ContentType = "application/octet-stream";
break;
}
Response.TransmitFile(file.FullName);
Response.End();
Response.Write("<script>window.close();</script>");
}