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

  • 相关阅读:
    C# 获取文件的修改时间、访问时间、创建时间
    Nhibernate Or多条件查询
    C# 将GridView当前页数据导成Execl
    C# 清空文件夹
    TreeView默认收缩
    JS控制控件的隐藏显示
    div置顶,不随滚动条滚动而滚动
    js 父窗体与子窗体的调用
    树形菜单的绑定以及链接
    2010.10.16 OA项目组一周报告 CQ
  • 原文地址:https://www.cnblogs.com/hdjjun/p/1223838.html
Copyright © 2011-2022 走看看