类似 MSDN CSDN 导航树效果 ASP.Net(C#) + JavaScript 实现!
2003-06-02 18:09
931 查看
使用该 URL http://localhost/WebApplicationX/WebForm1.aspx 在 Flashget 中下载
切换 暂停/开始 , 并增加下载的块数 测试!
原理参见上一篇 blog JSP/Servlet 实现版:
http://blog.csdn.net/playyuer/archive/2004/07/30/56538.aspx
利用该原理不难实现支持数据库大字段的断点续传多线程链接的下载!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string s = @"e:/northwind.mdb";
s = @"I://SetupRes//Sun//j2re-1_4_2_05-windows-i586-p.exe";
System.IO.Stream S = new System.IO.FileStream(s, System.IO.FileMode.Open, System.IO.FileAccess.Read,System.IO.FileShare.Read);
long p = 0;
long l = new System.IO.FileInfo(s).Length;
if (Request.Headers["Range"] != null)
{
Response.StatusCode = 206;
p = long.Parse( Request.Headers["Range"].Replace("bytes=","").Replace("-",""));
}
Response.AddHeader("Content-Length", ((long)(l - p)).ToString() );
if (p != 0)
{
//不是从最开始下载,
//响应的格式是:
//Content-Range: bytes [文件块的开始字节]-[文件的总大小 - 1]/[文件的总大小]
Response.AddHeader("Content-Range","bytes " + p.ToString() + "-" + ((long)(l - p)).ToString() + "/" + l.ToString());
}
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(s));
S.Position = p;
int i = 1;
byte[] b = new Byte[1024];
while (i > 0)
{
i = S.Read(b, 0, b.Length);
Response.OutputStream.Write(b, 0, i);
}
S.Close();
Response.End();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
切换 暂停/开始 , 并增加下载的块数 测试!
原理参见上一篇 blog JSP/Servlet 实现版:
http://blog.csdn.net/playyuer/archive/2004/07/30/56538.aspx
利用该原理不难实现支持数据库大字段的断点续传多线程链接的下载!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string s = @"e:/northwind.mdb";
s = @"I://SetupRes//Sun//j2re-1_4_2_05-windows-i586-p.exe";
System.IO.Stream S = new System.IO.FileStream(s, System.IO.FileMode.Open, System.IO.FileAccess.Read,System.IO.FileShare.Read);
long p = 0;
long l = new System.IO.FileInfo(s).Length;
if (Request.Headers["Range"] != null)
{
Response.StatusCode = 206;
p = long.Parse( Request.Headers["Range"].Replace("bytes=","").Replace("-",""));
}
Response.AddHeader("Content-Length", ((long)(l - p)).ToString() );
if (p != 0)
{
//不是从最开始下载,
//响应的格式是:
//Content-Range: bytes [文件块的开始字节]-[文件的总大小 - 1]/[文件的总大小]
Response.AddHeader("Content-Range","bytes " + p.ToString() + "-" + ((long)(l - p)).ToString() + "/" + l.ToString());
}
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(s));
S.Position = p;
int i = 1;
byte[] b = new Byte[1024];
while (i > 0)
{
i = S.Read(b, 0, b.Length);
Response.OutputStream.Write(b, 0, i);
}
S.Close();
Response.End();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
相关文章推荐
- 类似 MSDN CSDN 导航树效果 ASP.Net(C#) + JavaScript 实现!
- 类似 MSDN CSDN 导航树效果 ASP.Net(C#) + JavaScript
- 类似 MSDN CSDN 左边导航树效果的实现! [JavaScript + ASP]
- 类似 MSDN CSDN 左边导航树效果的实现! [JavaScript + ASP]
- JSP + JavaScript 实现类似 MSDN CSDN 导航树效果!
- JSP + JavaScript 实现类似 MSDN CSDN 导航树效果!
- 类似 MSDN CSDN 左边导航树效果的实现! [JavaScript +
- 类似 MSDN CSDN 左边导航树效果的实现! [JavaScript +
- ASP.NET(C#)AJAX+JAVASCRIPT实现类似QQ,MSN窗口之功能(续)
- 类似 MSDN CSDN 左边导航树效果的实现!
- JSP中使用SIteMesh实现类似asp.net母版效果
- 在asp.net中使用jQuery实现类似QQ网站的图片切割效果
- ASP.NET中运用xmlhttp实现无刷新数据传递(C# and JavaScript)
- ASP.NET的模板实现(C#) [ 来自:CSDN ]
- JavaScript提高:002:ASP.NET使用easy UI实现tab效果
- 使用javascript ajax C#实现类似百度的搜索框效果
- ASP.NET Boilerplate 学习 AspNet Core2 浏览器缓存使用 c#基础,单线程,跨线程访问和线程带参数 wpf 禁用启用webbroswer右键菜单 EF Core 2.0使用MsSql/MySql实现DB First和Code First ASP.NET Core部署到Windows IIS QRCode.js:使用 JavaScript 生成
- asp.net ajax实现类似交替项模板 和 光棒效果。
- Asp.net_用框架和target标记实现类似模版的效果
- ASP.NET 客户端回调实现 (C#) 示例 (VS2005)MSDN 错误处理