首页 > 代码库 > C# ASPX.NET 文件(图片)下载

C# ASPX.NET 文件(图片)下载

最好使用aspx页面写:

 1 protected void Page_Load(object sender,EventArgs e) 2 { 3      if(!IsPostBack) 4     { 5         System.Io.FileStream myFileStream = new System.Io.FileStream(Server.MapPath("",System.Io.FileMode.Open)); 6         long FileSize; 7         FileSize = myFileStream.Length; 8      byte[] Buffer = new byte[(int)FileSize]; 9         myFileStream.Read(Buffer,0,(int)myFileStream.Length);10         myFileStream.Close();11 12         Response.Clear();13         Response.ClearHeaders();14         Response.Content();15         Response.ContentType = "image/png";16         Response.AddHeader("content-disposition","attachment:filename="+"文件名.png",System.Text.Encoding.UTF8)17         Response.BinaryWrite(Buffer );18     }  19 }    

 

C# ASPX.NET 文件(图片)下载