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