您的当前位置:我要购书网>在线阅读>ASP/PHP/.NET/XML

asp.net中实现直接从网页上下载文件,而不须引用文件url来下载

来源:互联网  作者:  发布:我要购物网收集整理  发布时间:2006-8-31 人气:378

'函数名:ResponseFile'功能 :客户端从服务器端下载一个文件'返回值:返回True表示服务器响应成功,返回False表示失败'参数 :' PageResponse 响应客户端的Response对象,用Page.Response引用' DownloadFileName 客户端下载文件的文件名' LocalFilePath 服务器端待下载文件的路径' DownloadBuffer 服务器端读取文件的缓冲区大小,单位为KBPublic 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 TrueEnd Function
相关文章
· asc ii 完整码表及简介
· asp.net中实现直接从网页上下载文件,而不须引用文件..
· asp调用oracle存储过程
· asp.net环境下,vb.net语言,数据保存exce..
· asp.net中的mvc模式应用
· asp.net2.0+sql server2005构建多..
· asp实现的无限级会员树型结构
· asp.net2.0+sql server2005构建多..
· asp.net2.0+sql server2005构建多..
· asp中巧用response属性
热点文章
%>
· creating user controls
· 提高fastreplace速度 (fstrrep.pas)
· asc ii 完整码表及简介
· 自动生成拼音(汉字反查到拼音)
· sql2000无法安装的解决办法
· 浏览器集成教学 自定义浏览器
· vc++技术内幕(第四版)笔记(第7章)
· mysql5.0中文乱码解决方案
· sql server日期计算
· vc下利用ado连接access数据库
 淘宝旺旺:我要购书网上书店『图书目录
本购书中心地址: 杭州市延安路111号清波商厦南楼D座(总部) 上海市闸北区老沪太路网上购书中心(沪部),  邮编:310002
电子邮件:books@51goushu.com  经营许可证编号:沪ICP备06038574号
版权所有 2003-2008 © All Rights Reserved .购书网