asp.net 图片下载

         string fileName = "123.jpg";//图片名字
                    string filePath = Server.MapPath("../upload/123.jpg");//图片路径
       
                    //以字符流的形式下载文件
                    FileStream fs = new FileStream(filePath, FileMode.Open);
                    byte[] bytes = new byte[(int)fs.Length];
                    fs.Read(bytes, 0, bytes.Length);
                    fs.Close();
                    Response.ContentType = "application/octet-stream";
                    //通知浏览器下载文件而不是打开
                    Response.AddHeader("Content-Disposition", "attachment;  filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
                    Response.BinaryWrite(bytes);
                    Response.Flush();

//此处可以加上下载量的计算

         Response.End();

posted @ 2013-07-11 17:27  忆森灵  阅读(444)  评论(0编辑  收藏  举报