Enable the custom connection for file download to support resumable multi-thread link download of flashget! C #/ASP. NET implementation!

Source: Internet
Author: User
Use this URL to download http: // localhost/webapplicationx/webform1.aspx from flashget

Switch pause/start, and increase the number of downloaded parts!

For the principles, see the previous blog JSP/Servlet implementation version:

Http://blog.csdn.net/playyuer/archive/2004/07/30/56538.aspx

Using this principle, it is not difficult to implement multi‑thread download of resumable data transfer that supports large fields in the database!

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;

Response. addheader ("Accept-ranges", "bytes ");

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 the first download,
// The response format is:
// Content-range: bytes [start byte of the file block]-[total file size-1]/[total file 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 ();
}
# Generated by region web Form DesignerCode
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}

///

/// The designer supports the required methods-do not use the code editor to modify
/// Content 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.