Function Name: responsefile
Function: the client downloads an object from the server.
Return Value: True indicates that the server response is successful. False indicates that the server response fails.
Parameters:
Pageresponse responds to the client's response object and uses page. Response to reference
Downloadfilename the file name downloaded from the client
Localfilepath path of the file to be downloaded on the server
The buffer size of the downloadbuffer server for reading files, measured in KB.
Public Function responsefile (byref pageresponse as httpresponse, byval downloadfilename as string, byval localfilepath as string, byval downloadbuffer as long) as Boolean Dim reader as system. Io. filestream Dim buffer () as byte Dim filelength as long Dim filebuffer as long = 1024 * downloadbuffer Dim readcount as long Readcount = filebuffer Redim buffer (readcount-1) Try Reader = system. Io. file. openread (localfilepath) Filelength = reader. Length Try Pageresponse. Buffer = false Pageresponse. addheader ("connection", "keep-alive ") Pageresponse. contenttype = "application/octet-stream" Pageresponse. addheader ("content-disposition", "attachment; filename =" + downloadfilename) Pageresponse. addheader ("Content-Length", filelength. tostring) While readcount = filebuffer Readcount = reader. Read (buffer, 0, filebuffer) Redim preserve buffer (readcount-1) Pageresponse. binarywrite (buffer) End while Response. End () Catch ex as exception Return false Finally Reader. Close () End try Catch ex as exception Return false End try Return true End Function |