string filename = Session["file"] as string;
string path = Server.MapPath("~/files/" + filename);
if (File.Exists(path))
{
FileInfo fi = new FileInfo(path);
Response.Clear();
Response.ClearHeaders();
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8).Replace("+", "%20"));
Response.AppendHeader("Content-Length", fi.Length.ToString());
Response.WriteFile(fi.FullName);
Response.Flush();
Response.End();
}
else
{
Response.Write("文件不存在");
}
转载于:https://www.cnblogs.com/solomon_Blog/archive/2011/08/13/2137099.html