码迷,mamicode.com
首页 > Windows程序 > 详细

C# 关于下载文档操作功能

时间:2015-06-23 17:43:28      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

/// <summary>
        /// 征信材料
        /// </summary>
        /// <param name="fileName"></param>
        public void DownLoad(string fileName = "金融交易平台-搜房金融管理后台使用说明V1.1.pdf")
        {
            string browser = Request.UserAgent.ToUpper();
            FileStream filestream = new FileStream(Server.MapPath("/Manager/Attach/" + fileName), FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
            long filesize = filestream.Length;
            //让客户端浏览器正确识别这个文件的类型和文件大小
            System.IO.Path.GetFileName(Server.MapPath("/Manager/Attach/" + fileName)).ToLower();
            Response.ContentType = "application/octet-stream";
            if (browser.Contains("FIREFOX") == true)
            {
                fileName = fileName;
            }
            else
            {
                fileName = HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);

            }
            Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\";");
            Response.AddHeader("Content-Length", filesize.ToString());
            //将文件中的数据发送到客户端
            byte[] filebuffer = new byte[filesize];
            filestream.Read(filebuffer, 0, (int)filesize);
            Response.BinaryWrite(filebuffer);

            filestream.Close();
            Response.End();
        }

C# 关于下载文档操作功能

标签:

原文地址:http://www.cnblogs.com/eric-gms/p/4595711.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!