国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET中實現直接從網頁上下載文件

2024-07-10 13:07:42
字體:
來源:轉載
供稿:網友

函數名: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 

  • 本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。
  • 發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 游戏| 微山县| 绩溪县| 中方县| 公主岭市| 昆明市| 望奎县| 名山县| 渑池县| 永德县| 板桥市| 宽甸| 探索| 阆中市| 陆川县| 滁州市| 区。| 南岸区| 鄂伦春自治旗| 忻州市| 贵港市| 三亚市| 乌鲁木齐县| 富平县| 吴桥县| 林甸县| 四子王旗| 苗栗市| 五指山市| 瑞金市| 通城县| 栾川县| 贺州市| 泰顺县| 白朗县| 扎鲁特旗| 齐河县| 玛沁县| 平昌县| 象山县| 扎鲁特旗|