zoukankan      html  css  js  c++  java
  • 分块下载,测试文件 3.8GB

    protected void Page_Load(object sender, EventArgs e)
        {
            string downFilePath = @"D:\openSUSE-10.2-GM-DVD-i386.iso"; // test with 3.8GB, ok // Server.MapPath("~/files/somefile.iso");
            System.IO.FileInfo downFileInfo = new System.IO.FileInfo(downFilePath);

            if (!downFileInfo.Exists) throw new Exception("文件不存在。");
            const int CHUNK_SIZE = 10000;
            byte[] buffer = new byte[CHUNK_SIZE];

            Response.Clear();
            using (System.IO.FileStream iStream = System.IO.File.OpenRead(downFilePath)) {
                long dataLengthToRead = iStream.Length;
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition",
                                   "attachment; filename=" + Server.UrlPathEncode(downFileInfo.Name));
                while (dataLengthToRead > 0 && Response.IsClientConnected) {
                    int lengthRead = iStream.Read(buffer, 0, CHUNK_SIZE);
                    Response.OutputStream.Write(buffer, 0, lengthRead);
                    Response.Flush();
                    dataLengthToRead = dataLengthToRead - lengthRead;
                }
            }
             }


     

    Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1686797

  • 相关阅读:
    【转】Asp.net页面的生命周期
    指定.net的httprequest http协议版本为1.0
    查看oracle中被锁的对象(表...)
    网友整理的Flex开源项目
    oracle中用profile限定用户资源
    (转)让你受益终身的10个Word实用技巧
    磁盘阵列卡
    Nmap扫描器的使用
    最简单的数据库连接,asp连接access数据库
    网络经典命令行
  • 原文地址:https://www.cnblogs.com/hdjjun/p/1223838.html
Copyright © 2011-2022 走看看