Function Name: Responsefile
Function: Client downloads a file from the server side
Return value: Returns TRUE indicates that the server responded successfully and False indicates failure
Parameters:
Pageresponse respond to the response object of the client, using the Page.Response reference
DownloadFileName the filename of the client download file
Localfilepath the path of the server-side file to be downloaded
Downloadbuffer the buffer size, in kilobytes, of the server-side read file
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 |