Asp tutorial. net (c #) multi‑thread breakpoint resume
Stream istream = null;
Byte [] buffer = new byte [10240]; // buffer block 10 k bytes:
Int length;
Long datatoread;
String filepath = @ "e: softwaresql server 2000 personal edition. iso ";
String filename = system. io. path. getfilename (filepath );
Try
{
// Open the file istream = new filestream (filepath, filemode. open, fileaccess. read, fileshare. read );
Response. clear ();
Datatoread = istream. length;
Long p = 0;
If (request. headers ["range"]! = Null)
{
Response. statuscode = 206;
P = long. parse (request. headers ["range"]. replace ("bytes =", ""). replace ("-",""));
}
If (p! = 0)
{
Response. addheader ("content-range", "bytes" + p. tostring () + "-" + (long) (datatoread-1 )). tostring () + "/" + datatoread. tostring ());
}
Response. addheader ("content-length", (long) (datatoread-p). tostring ());
Response. contenttype = "application/octet-stream ";
Response. addheader ("content-disposition", "attachment; filename =" + system. web. httputility. urlencode (request. contentencoding. getbytes (filename )));
Istream. position = p;
Datatoread = datatoread-p;
While (datatoread> 0)
{
If (response. isclientconnected)
{
Length = istream. read (buffer, 0, 10240 );
Response. outputstream. write (buffer, 0, length );
Response. flush ();
Buffer = new byte [10240];
Datatoread = datatoread-length;
}
Else
{
// If the user disconnects, prevent the infinite loop datatoread =-1;
}
}
}
Catch (exception ex)
{
Response. write ("error:" + ex. message );
}
Finally
{
If (istream! = Null)
{
Istream. close ();
}
Response. end ();
}
}