All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
查询表里面有N组相同的记录经典SQL语句_[SQL Server教程]
用ASP.NET,2.0,FormView控件控制显示_.net资料_编程技术
十天学会ASP.net,第五天_.net资料_编程技术
了解Hibernate的FlushMode.NEVER_.net资料_编程技术
组合.NET数据控件构建强大用户接口_.net资料_编程技术
C#教程:COM+的概念
配置整合Win+Apache+PHP+MySQL+Tcomcat(或Resin)完全手册_php资料_编程技术
在PHP中全面阻止SQL注入式攻击之三_[PHP教程]
ASP.NET从零起步设计网站全过程(4)_[Asp.Net教程]
SQL,Server,2005,Reporting,Services,初次使用感受_[SQL,Server教程]
Reading number is top 10 pictures
陪睡门马睿菈自曝写真 称首拍大尺度照片1
深圳的风光
Born After 90 Beijing sports university campus flower photos4
美女浴室写真3
NeedWallpaper5
The real super beauty7
So beauty, will let you spray blood3
青春清纯美女大集合3
Go to the national museum2
Absolutely shocked. National geographic 50 animal photographys3
Download software ranking
dreamweaver8中文版
Such love down(擒爱记)
尖东毒玫瑰B
matrix3
Unix video tutorial3
Boxer's Top ten classic battle1
Twenty piece of palm leaf
Detective task-the top secret prostitution files
Unix video tutorial11
Tram sex maniac 2 (H) rar bag7
delv published in(发表于) 2014/1/27 6:47:32 Edit(编辑)
Asp.net(c#)实现多线程断点续传_[Asp.Net教程]

Asp.net(c#)实现多线程断点续传_[Asp.Net教程]

Asp.net(c#)实现多线程断点续传_[Asp.Net教程]

  以前一直错误的认为在ASP.NET中无法通过编程方式实现多线程断点续传,今天终于获得了这样一个解决方案,让我明白要学习的东西还很多。
  此解决方案基于其它解决方案及相关资料,根据我自己的理解改进.如有错漏,请尽管指出;如有其它更好的解决方案,请推荐一下,感谢先。



System.IO.Stream iStream = null;


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


// Length of the file:
int length;


// Total bytes to read:
long dataToRead;


// Identify the file to download including its path.
string filepath = @"E:\software\SQL Server 2000 Personal Edition.ISO";


// 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);
Response.Clear();


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


long p = 0;
if(Request.Headers["Range"]!=null)
{
Response.StatusCode = 206;
p = long.Parse( Request.Headers["Range"].Replace("bytes=","").Replace("-",""));
}
if(p != 0)
{
Response.AddHeader("Content-Range","bytes " + p.ToString() + "-" + ((long)(dataToRead - 1)).ToString() + "/" + dataToRead.ToString());
}
Response.AddHeader("Content-Length",((long)(dataToRead-p)).ToString());
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(Request.ContentEncoding.GetBytes(filename)));


iStream.Position = p;
dataToRead = dataToRead - p;
// 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, 10240);


// 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[10240];
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();
}
Response.End();
}

来源:cnblogs







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.