C # breakpoint resume

xiaoxiao2021-03-06  109

System.io.Stream Istream

=

NULL

;

//

Buffer to read 10k bytes in chunk:

Byte

[] Buffer

=

New

BYTE [

10240

];

//

Length of the file:

int

Length;

//

Total bytes to read:

Long

Datatoread;

//

Identify The File to Download Including ITS Path.

String

FilePath

=

@ "

E: / Software / SQL Server 2000 Personal Edition.iso

"

;

//

Identify the file name.

String

Filename

=

System.io.path.GetFileName (FilePath);

Try

{// Open the file. Istream = new system.io.filestream (FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.Fileshare.Read; response.clear (); / / Total bytes to read: 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) ((long) DatatoreAD-P)). TOSTRING ()); response.contentType = "Application / OCTET-stream"; response.addheader ("Content-Dispo sition "," attachment; filename = " System.Web.HttpUtility.UrlEncode (Request.ContentEncoding.GetBytes (filename))); iStream.Position = p; dataToRead = dataToRead - p; // Read the bytes while (dataToRead. > 0) {// Verify That The Client IS Connected. If (Response.isclientConnected) {// read the data in buffer. Length = istream.read (buffer, 0, 10240);

// Write the data to the capital output.outputstream.write (buffer, 0, length); // flush the data to the html output. Response.flush (); buffer = new byte [10240]; datatoread = Datatoread - length;} else {// prevent infinite loop if user disponnects datatoread = -1;}}} catch

(Exception EX)

{// trap the error, if any. Response.write ("Error:" ex. measureage);

Finally

{IF (iStream! = Null) {// close the file. Istream.close ();} response.end ();}

转载请注明原文地址:https://www.9cbs.com/read-126702.html

New Post(0)