资源简介
Asp.net多线程下载示例源码Asp.net多线程下载示例源码
代码片段和文件信息
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
using AjaxPro;
using System.Threading;
using System.IO;
using DownLoadComponent;
///
/// Author: [ ChengKing(ZhengJian) ]
/// Blog: Http://blog.csdn.net/ChengKing
//该源码下载自www.51aspx.com(51aspx.com)
/// 扩展如下功能:
/// 1. 解决一些线程相关的Bug;
/// 2.扩展用控制文件实现断点续传功能.
///
public partial class _Default : System.Web.UI.Page
{
//全局变量
private static object _SyncLockobject = new object();
protected void Page_Load(object sender EventArgs e)
{
Utility.RegisterTypeForAjax(typeof(_Default));
this.TextBox1.Text = “http://download.csdn.net/filedown/aHR0cDovL2Rvd25sb2FkMS5jc2RuLm5ldC9kb3duMy8yMDA3MDQxOS8xOTE1NTU0NzgwMS5yYXI=!169105“;
}
protected void btOK_Click(object sender EventArgs e)
{
this.Label1.Text = “状态: 正在下载...“;
DownLoadComponent.HttpWebClient x = new DownLoadComponent.HttpWebClient();
//注册 DataReceive 事件
x.DataReceive += new DownLoadComponent.HttpWebClient.DataReceiveEventHandler(this.x_DataReceive);
//注册 ExceptionOccurrs 事件
x.ExceptionOccurrs += new DownLoadComponent.HttpWebClient.ExceptionEventHandler(this.x_ExceptionOccurrs);
string Source = this.TextBox1.Text.Trim();
string FileName = Source.Substring(Source.LastIndexOf(“/“) + 1);
string Location= System.IO.Path.Combine( this.TextBox2.Text.Trim() FileName);
//F: 源服务器文件; _f: 保存路径; 10: 自设定一个文件有几个线程下载.
x.DownloadFile(SourceLocation int.Parse(this.TextBox3.Text));
//Response.Write(“正在下载文件...“);
this.btOK.Enabled = false;
this.btCancel.Enabled = true;
}
private void x_DataReceive(DownLoadComponent.HttpWebClient Sender DownLoadComponent.DownLoadEventArgs e)
{
string f = e.DownloadState.FileName;
if (e.DownloadState.AttachmentName != null)
f = System.IO.Path.GetDirectoryName(f) + @“\“ + e.DownloadState.AttachmentName;
using (System.IO.FileStream sw = new System.IO.FileStream(f System.IO.FileMode.OpenOrCreate System.IO.FileAccess.ReadWrite System.IO.FileShare.ReadWrite))
{
sw.Position = e.DownloadState.Position;
sw.Write(e.DownloadState.Data 0 e.DownloadState.Data.Length);
sw.Close();
}
}
private void x_ExceptionOccurrs(DownLoadComponent.HttpWebClient Sender DownLoadComponent.ExceptionEventArgs e)
{
System.Console.WriteLine(e.Exception.Message);
//发生异常重新下载相当于断点续传你可以自己自行选择处理方式或自行处理
DownLoadComponent.HttpWebClient x = new DownLoadComponent.HttpWebClient();
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1809 2007-06-22 14:11 51aspx源码必读.txt
文件 3766 2007-06-22 14:14 Default.aspx
文件 6284 2007-06-22 14:14 Default.aspx.cs
文件 1748 2007-05-30 19:45 Web.config
文件 125 2007-03-27 14:33 最新Asp.Net源码下载.url
文件 38119 2007-06-22 14:15 App_Code\DownLoadState.cs
目录 0 2007-06-22 11:46 App_Code
文件 81920 2005-11-04 11:59 Bin\AjaxPro.dll
文件 246 2007-05-30 18:56 Bin\AjaxPro.dll.refresh
目录 0 2007-06-22 11:46 Bin
----------- --------- ---------- ----- ----
134017 10
- 上一篇:asp.net多线程日志记录源码
- 下一篇:C#AE最短路径输入查询
评论
共有 条评论