欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp 读取文件和保存文件函数代码

程序员文章站 2023-08-24 11:51:19
'************************************* '读取文件 '************************************* fu...
'*************************************
'读取文件
'*************************************

function loadfromfile(byval file)
dim objstream
dim rtext
rtext = array(0, "")
set objstream = server.createobject("adodb.stream")
with objstream
.type = 2
.mode = 3
.open
.charset = "utf-8"
.position = objstream.size
on error resume next
.loadfromfile server.mappath(file)
if err then
rtext = array(err.number, err.description)
loadfromfile = rtext
err.clear
exit function
end if
rtext = array(0, .readtext)
.close
end with
loadfromfile = rtext
set objstream = nothing
end function

'*************************************
'保存文件
'*************************************

function savetofile(byval strbody, byval file)
dim objstream
dim rtext
rtext = array(0, "")
set objstream = server.createobject("adodb.stream")
with objstream
.type = 2
.open
.charset = "utf-8"
.position = objstream.size
.writetext = strbody
on error resume next
.savetofile server.mappath(file), 2
if err then
rtext = array(err.number, err.description)
savetofile = rtext
err.clear
exit function
end if
.close
end with
rtext = array(0, "保存文件成功!")
savetofile = rtext
set objstream = nothing
end function