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
}