当前位置: 首页 > 图文教程 > 网络编程 > ASP > asp之基于adodb.stream的文件操作类

ASP
ASP技巧研究:ASP Error对象的相关知识
ASP模拟MVC模型的编程方式
学ASP应该注意ASP程序书写的规范
用文本+ASP打造新闻发布系统
ASP Session对象的集合以及属性方法事件
ASP防止盗链或防止下载的方法
ASP开发中存储过程应用详解
ASP脚本语言的19个基本技巧使用
ASP中使用Form和QueryString集合
在ASP中访问和更新Cookies集合
在ASP中操作HTTP报头方法分析
建立三层结构的ASP应用程序
ASP动态网页编程的19个基本技巧
ASP教程:制作登陆验证页面程序
asp正则表达式详细说明
使用ASP订制自己的XML文件读写方法
ASP中的Debug类--VBScript
Asp中如何设计跨越域的Cookie
DHTML+XML+ASP+CSS的树形目录
实例一则 ASP程序中输出Excel文件

ASP 中的 asp之基于adodb.stream的文件操作类


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 106 ::
收藏到网摘: n/a

复制代码 代码如下:

<%
'*************************************************************
'转发时请保留此声明信息,这段声明不并会影响你的速度!
'*************************************************************

'*************************************************************
'@author: 面条
'@realname: 徐仁禄
'@email: [email protected]
'@QQ: 55547082
'@Homepage: http://www.ksdn.net
'@版权申明:
' 非盈利性质团体或者个人可以免费使用.
'*************************************************************

'*************************************************************
' 类名称: files
' 类功能: 实现文件读写功能,利用adodb.stream实现,在不支持fso的主机上也可以读写文件.
'*************************************************************
class files

private adSaveCreateOverWrite '创建文件的时候可以覆盖已经存在的文件.
private adSaveCreateNotExist '保存文件的时候如果文件不存在,可以创建文件.

'*************************************************************
' 事件名称: Class_Initialize()
' 事件发生条件: 类创建时候产生该事件
' 事件内容: 给私有变量赋值
' 事件传入参数: 无
'*************************************************************

sub Class_Initialize()
adSaveCreateOverWrite =2
adSaveCreateNotExist = 1
end sub

'*************************************************************
' 函数名称: function readfile(filepath)
' 函数内容: 读出文件
' 传入参数: filepath:要读的文件的绝对路径
' 返回参数: 要读的文件的内容.
'*************************************************************
function readfile(filepath)

on error resume next
dim stm2

set stm2 =server.createobject("ADODB.Stream")
stm2.Charset = "gb2312"
stm2.Open
stm2.LoadFromFile filepath
readfile = stm2.ReadText
end function

'*************************************************************
' 函数名称: function writefile(filepath,str)
' 函数内容: 写入文件
' 传入参数: filepath:要读的文件的绝对路径
' str: 要写入的内容
' 返回参数: 无返回
'*************************************************************
function writefile(filepath,str)
on error resume next
Set stm = server.createobject("ADODB.Stream")
stm.Charset = "gb2312"
stm.Open
stm.WriteText str
stm.SaveToFile filepath, adSaveCreateOverWrite
end function

'*************************************************************
' 函数名称: function copy(filepath_s,filepath_d)
' 函数内容: 读出文件
' 传入参数: filepath_d:目的文件的绝对路径
' filepath_s:源文件路径
'*************************************************************
function copy(filepath_s,filepath_d)
on error resume next
dim stm2
set stm2 =server.createobject("ADODB.Stream")
stm2.Charset = "gb2312"
stm2.Open
stm2.LoadFromFile filepath_s
stm2.SaveToFile filepath_d, adSaveCreateOverWrite
end function
end class
%>