首页 > Web开发 > 详细

ASP.NET Response 下载文件

时间:2017-08-27 12:39:51      阅读:279      评论:0      收藏:0      [点我收藏+]
  private void DownLoad(string fileName, string path)
        {
            FileInfo fi = new FileInfo(path);

            if (fi.Exists)
            {
                Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();
                Response.Buffer = true;

                Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
                Response.AddHeader("Content-Length", fi.Length.ToString());
                Response.AddHeader("Content-Transfer-Encoding", "binary");
                Response.ContentType = "application/octet-stream";
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");

                Response.WriteFile(path);
                Response.Flush();
                Response.End();
            }
        }

        private void DownLoad2(string fileName, string path)
        {
            FileInfo fi = new FileInfo(path);

            if (fi.Exists)
            {
                Response.Clear();
                Response.Buffer = true;

                Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
                Response.ContentType = "application/unknow";

                Response.TransmitFile(path);
                Response.End();
            }
        }

 

ASP.NET Response 下载文件

原文:http://www.cnblogs.com/ligenyun/p/7439933.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!