下载
来源:互联网 发布:查询自己电脑端口 编辑:程序博客网 时间:2024/04/18 22:01
if (Session["txt"] != "")
{ //获取文件路径
string path = Server.MapPath("File/") + Session["txt"].ToString();
//初始化 FileInfo 类的实例,它作为文件路径的包装
FileInfo fi = new FileInfo(path);
//判断文件是否存在
if (fi.Exists)
{
//将文件保存到本机上
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fi.Name));
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Filter.Close();
Response.WriteFile(fi.FullName);
Response.End();
}
}
{ //获取文件路径
string path = Server.MapPath("File/") + Session["txt"].ToString();
//初始化 FileInfo 类的实例,它作为文件路径的包装
FileInfo fi = new FileInfo(path);
//判断文件是否存在
if (fi.Exists)
{
//将文件保存到本机上
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fi.Name));
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Filter.Close();
Response.WriteFile(fi.FullName);
Response.End();
}
}