惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
T
Threat Research - Cisco Blogs
S
SegmentFault 最新的问题
V2EX - 技术
V2EX - 技术
Hacker News: Ask HN
Hacker News: Ask HN
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
P
Proofpoint News Feed
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
C
Cybersecurity and Infrastructure Security Agency CISA
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
U
Unit 42
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
H
Help Net Security
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 热门话题
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
H
Heimdal Security Blog
博客园 - 聂微东
S
Securelist
大猫的无限游戏
大猫的无限游戏
Cloudbric
Cloudbric
Cisco Talos Blog
Cisco Talos Blog

博客园 - Angelo Dell'inferno

[ASP.NET] 基于.Net Remoting 的网站访问监控模块 [转]Run a Http Response Filter together with an Ajax Update Panel [ASP.NET] HyperLink + Image 实现动态图片链接 [ASP.NET] (转)地址栏参数的判断 [ASP.NET] 实现Label自动换行 [ASP.NET] 验证码生成 [ASP.NET] 实现客户端浏览服务端目录的页面 [ASP.NET]Treeview 控件显示服务端目录文件夹及文件 [C#] GridView导出到Excel [C#] 获取两个时间点的时间间隔 [SQL Server][转]数据库并发控制——活锁&死锁 [JavaScript] 防止页面被嵌入Iframe [SQL Server] 存储过程事务 [SQL Server] T-SQL 连接数据库方法 [C#] 杀Excel进程 [ASP.NET] (原创)自定义GridView分页 [C#] 将DataSet内容导入到Excel (矩阵区域导出) [Oracle] 日期相关操作 [ORACLE] 函数大全
[ASP.NET] 服务器端下载文件实现
Angelo Dell'inferno · 2007-12-10 · via 博客园 - Angelo Dell'inferno

            string _fileName = HttpContext.Current.Server.MapPath("~\\report\\FactReports\\") + e.Item.Cells[0].Text.Trim(); //服务器端文件路径
            //建立文件对象
            FileStream myFile = new FileStream(_fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            //建立流读对象
            BinaryReader br = new BinaryReader(myFile);
            Response.AddHeader("Accept-Ranges", "bytes");
            Response.Buffer = false;
            long fileLength = myFile.Length;
            long startBytes = 0;

            int pack = 10240; //10K bytes
            //int sleep = 200;   //每秒5次   即5*10K bytes每秒
            int sleep = (int)Math.Floor(1000 * pack / 1024000) + 1;
            if (Request.Headers["Range"] != null)
            {
                Response.StatusCode = 206;
                string[] range = Request.Headers["Range"].Split(new char[] {'=', '-'});
                startBytes = Convert.ToInt64(range[1]);
            }
            Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
            if (startBytes != 0)
            {
                Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength-1, fileLength));
            }
            Response.AddHeader("Connection", "Keep-Alive");
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition","attachment;filename=" + HttpUtility.UrlEncode(_fileName,System.Text.Encoding.UTF8) );

            br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
            int maxCount = (int) Math.Floor((fileLength - startBytes) / pack) + 1;
            for (int i = 0; i < maxCount; i++)
            {
                if (Response.IsClientConnected)
                {
                    Response.BinaryWrite(br.ReadBytes(pack));
                    Thread.Sleep(sleep);
                }
                else
                {
                    i=maxCount;

                }
            }
            myFile.Close();
            br.Close();
            Response.End();