网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > C#应用
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.C++与C#混合生成.NET程序 .
.由C++转向C#:我们需要注意哪些方.
.C#中的接口.
.使用C#创建SQL Server的存储过程.
.在Linux中使用C#.
.用Visual C#来清空回收站(1).
.用C#开发.NET CF 蓝牙通信模块.
.Visual C#2005中使用正则表达式.
.用C#下的Raw Socket编程实现网络.
.在C#中建立复杂的、灵活的SQL查询.
.在C#中加载自己编写的动态链接库.
.C#中为DataGrid添加下拉列表框.
..NET下对二进制文件进行加密解密.
.图片保存到数据库和从数据库读取.
.C# 文件操作(上传 下载 删除 文件.
.C#使用指针.
.如何在控件的设计时得到窗体设计.
.C#中计算两个时间的差.
.C#中使用net share命令时要注意的.
.用Visual C#中实现DB2数据库编程.

C#实现大文件分块发送到客户端

发表日期:2004-11-18


System.IO.Stream iStream = null;

 // Buffer to read 10K bytes in chunk:
 byte[] buffer = new Byte[10000];

 // Length of the file:
 int length;

 // Total bytes to read:
 long dataToRead;

 // Identify the file to download including its path.
 string filepath  = "DownloadFileName";

 // Identify the file name.
 string  filename  = System.IO.Path.GetFileName(filepath);

 try
 {
  // Open the file.
  iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open,
     System.IO.FileAccess.Read,System.IO.FileShare.Read);


  // Total bytes to read:
  dataToRead = iStream.Length;

  Response.ContentType = "application/octet-stream";
  Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);

  // Read the bytes.
    while (dataToRead > 0)
  {
   // Verify that the client is connected.
   if (Response.IsClientConnected)
   {
    // Read the data in buffer.
    length = iStream.Read(buffer, 0, 10000);

    // Write the data to the current output stream.
    Response.OutputStream.Write(buffer, 0, length);

    // Flush the data to the HTML output.
    Response.Flush();

    buffer= new Byte[10000];
    dataToRead = dataToRead - length;
   }
   else
   {
    //prevent infinite loop if user disconnects
    dataToRead = -1;
   }
  }
 }
 catch (Exception ex)
 {
  // Trap the error, if any.
  Response.Write("Error : " + ex.Message);
 }
 finally
 {
  if (iStream != null)
  {
   //Close the file.
   iStream.Close();
  }
 }

 

上一篇:C#实现SMTP服务器,使用TCP命令实现,功能比较完善 人气:15926
下一篇:使用C#编写一个计时器 人气:16326
浏览全部C#的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐