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(); } } |