函数名:responsefile
功能 :客户端从服务器端下载一个文件
返回值:返回true表示服务器响应成功,返回false表示失败
参数 :
pageresponse 响应客户端的response对象,用page.response引用
downloadfilename 客户端下载文件的文件名
localfilepath 服务器端待下载文件的路径
downloadbuffer 服务器端读取文件的缓冲区大小,单位为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 |
新闻热点
疑难解答
图片精选