转自: http://dev.mjxy.cn/a-Download-the-file-to-stream-download-hide-the-real-path.aspx
以流的方式下载文件,隐藏实际的下载路径
01 |
string path = Server.MapPath( "~/UploadFiles/" + "a.doc" ); |
02 |
System.IO.FileInfo file = new System.IO.FileInfo(path); |
05 |
Response.AddHeader( "Content-Disposition" , "attachment; filename=" + file.Name); |
07 |
Response.AddHeader( "Content-Length" , file.Length.ToString()); |
08 |
Response.ContentType = "application/octet-stream" ; |
09 |
Response.WriteFile(file.FullName); |
12 |
public void down( string cc) |
17 |
string path = System.Web.HttpContext.Current.Server.MapPath(cc); |
18 |
System.IO.FileInfo file = new System.IO.FileInfo(path); |
21 |
System.Web.HttpContext.Current.Response.Clear(); |
22 |
System.Web.HttpContext.Current.Response.AddHeader( "Content-Disposition" , "attachment; filename=" + file.Name); |
24 |
System.Web.HttpContext.Current.Response.AddHeader( "Content-Length" , file.Length.ToString()); |
26 |
System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream" ; |
28 |
System.Web.HttpContext.Current.Response.Filter.Close(); |
29 |
System.Web.HttpContext.Current.Response.WriteFile(file.FullName); |
30 |
System.Web.HttpContext.Current.Response.End(); |
34 |
System.Web.HttpContext.Current.Response.Write( "文件不存在" ); |
35 |
System.Web.HttpContext.Current.Response.End(); |