asp.net 文件下载技术
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("文件不存在");
}