Public Static Bool Responsefile (System.Web.httpRequest _Request,
System.Web.httpResponse_response,
String _filename, string _fullpath, long _speed)
{
Try
{
FileStream myfile = new filestream (_FullPath, Filemode.open, FileAccess.Read, Fileshare.Readwrite);
BinaryReader Br = New BinaryReader (MyFile);
Try
{
_RESPONSE.ADDHEADER ("Accept-Ranges", "Bytes");
_RESPONSE.BUFFER = FALSE;
Long fileLength = myfile.length;
Long StartBytes = 0;
INT PACK = 10240; // 10K Bytes
IF (_Request.Headers ["Range"]! = NULL)
{
_RESPONSE.STATUSCODE = 206;
String [] Range = _Request.Headers ["Range"]. split (new char [] {'=', '-'});
StartBytes = Convert.Toint64 (Range [1]);
}
_RESPONSE.ADDHEADER ("Content-Length", (FileLength - StartBytes) .tostring ());
IF (startBytes! = 0)
{
_RESPONSE.ADDHEADER ("Content-Range", String.Format ("Bytes {0} - {1} / {2}", StartBytes, FileLength-1, FileLength);
}
_RESPONSE.ADDHEADER ("Connection", "Keep-alive");
_RESPONSE.CONTENTTYPE = "Application / Oct-stream";
_RESPONSE.ADDHEADER ("Content-Disposition", "attachment; filename =" system.web.httputility.urlencode (_FileName, System.Text.Encoding.utf8));
Br.BaseStream.seek (StartBytes, seekorigin.begin);
Int maxcount = (int) Math.floor (FileLength - StartBytes) / PACK 1;
Byte [] buffer = new byte [pack];
For (int i = 0; i { IF (_RESPONSE.ISCLIENTCONNECTED) { Buffer = br.readbytes (pack); _RESPONSE.OUTPUTSTREAM.WRITE (Buffer, 0, PACK); _RESPONSE.FLUSH (); Buffer = new byte [Pack]; } Else { I = MAXCOUNT; } } } Catch (Exception myerror) { Throw myerror; } Finally { br.close (); myfile.close (); } } Catch (Exception MyError) { Throw myerror; } Return True; }