文件下载

来源:互联网 发布:java中的泛型是什么 编辑:程序博客网 时间:2024/05/06 09:53

参数说明
AbsPath:文件绝对路径
FileName:文件原名
public static void DownloadFile(string AbsPath,string FileName)
{
FileStream fs = new FileStream(AbsPath, FileMode.Open, FileAccess.Read);
BinaryReader r = new BinaryReader(fs);
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename="+FileName);
// System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;FileName");
System.Web.HttpContext.Current.Response.Charset = "GB2312";
System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
System.Web.HttpContext.Current.Response.BinaryWrite(r.ReadBytes(Convert.ToInt32(fs.Length)));
System.Web.HttpContext.Current.Response.Flush() ;
}

原创粉丝点击