asp.net大文件下载

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 22:27 点击:

一个可尝试的方案,使用二进制流下载,下载地址是诸如   http://www.abc.com/down.apsx?fileid=911199   这样的连接,在   down   页面进行权限判断,比如是否登录了,当前用户的点数是否满足   911199   对应的文件的下载点数   等等

二进制下载实例代码,支持特大文件下载

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();
                //   fails   to   down   the   big   file   with   both   the   following   methods
                //   error:   System.ArgumentOutOfRangeException:   大小参数必须介于零和最大的   Int32   值之间。
                //   Response.WriteFile(downFilePath);
                //   OR
                //   Response.TransmitFile(downFilePath);   //   ASP.NET   2.0   supported
                //
                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));   //   对文件名进行编

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • 浅析.NET下XML数据访问新机制
      • asp.net 面试+笔试题目第1/2页
      • C# 邮件地址是否合法的验证
      • asp.net 设置GridView的选中行的实现代码
      • C#高级编程:数据库连接[1]
      • 经典C++程序1
      • IIS 自动回收导致后台定时器失效的问题解决
      • ASP.NET GridView列表代码示例
      • Asp.net MVC源码分析--Action Filter的链式调用
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1