The custom connection that enables the file to download supports the FlashGet breakpoint to continue to download the multithreading link! C#/asp.net implementation

Source: Internet
Author: User
Tags continue range tostring
asp.net| Multithreading | link | download

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)
{
Not downloaded from the beginning,
The format of the response is:
content-range:bytes [File Block start byte]-[Total size of file-1]/[file Total size]
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 ();
}
Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}

///
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
///
private void InitializeComponent ()
{
This. Load + = new System.EventHandler (this. Page_Load);
}
#endregion
}




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.