ADODB.Stream 写文本文件相关的 ASP 函数
作者:parno 日期:2013-01-18
复制内容到剪贴板 程序代码
<%
'================================================
'函数名:CreatedTextFile
'作 用:创建文本文件
'参 数:FileName
'================================================
Public Function CreatedTextFile(ByVal FileName, ByVal body)
On Error Resume Next
If InStr(FileName, ":") = 0 Then FileName = Server.MapPath(FileName)
Dim oStream
Set oStream = CreateObject("ADODB.Stream")
oStream.Type = 2 '设置为可读可写
oStream.Mode = 3 '设置内容为文本
oStream.Charset = "UTF-8" '设置编码
oStream.Open
oStream.Position = oStream.Size
oStream.WriteText body
oStream.SaveToFile FileName, 2
oStream.Close
Set oStream = Nothing
If Err.Number <> 0 Then Err.Clear
End Function
'================================================
'函数名:Readfile
'作 用:读取文件内容
'参 数:fromPath —-来源文件路径
'================================================
Public Function Readfile(ByVal fromPath)
On Error Resume Next
Dim strTemp,fso,f
If InStr(fromPath, ":") = 0 Then fromPath = Server.MapPath(fromPath)
Set fso = Server.CreateObject(FSO_ScriptName)
If fso.FileExists(fromPath) Then
Set f = fso.OpenTextFile(fromPath, 1, True)
strTemp = f.ReadAll
f.Close
Set f = Nothing
End If
Set fso = Nothing
Readfile = strTemp
If Err.Number <> 0 Then Err.Clear
End Function
'================================================
%>
'================================================
'函数名:CreatedTextFile
'作 用:创建文本文件
'参 数:FileName
'================================================
Public Function CreatedTextFile(ByVal FileName, ByVal body)
On Error Resume Next
If InStr(FileName, ":") = 0 Then FileName = Server.MapPath(FileName)
Dim oStream
Set oStream = CreateObject("ADODB.Stream")
oStream.Type = 2 '设置为可读可写
oStream.Mode = 3 '设置内容为文本
oStream.Charset = "UTF-8" '设置编码
oStream.Open
oStream.Position = oStream.Size
oStream.WriteText body
oStream.SaveToFile FileName, 2
oStream.Close
Set oStream = Nothing
If Err.Number <> 0 Then Err.Clear
End Function
'================================================
'函数名:Readfile
'作 用:读取文件内容
'参 数:fromPath —-来源文件路径
'================================================
Public Function Readfile(ByVal fromPath)
On Error Resume Next
Dim strTemp,fso,f
If InStr(fromPath, ":") = 0 Then fromPath = Server.MapPath(fromPath)
Set fso = Server.CreateObject(FSO_ScriptName)
If fso.FileExists(fromPath) Then
Set f = fso.OpenTextFile(fromPath, 1, True)
strTemp = f.ReadAll
f.Close
Set f = Nothing
End If
Set fso = Nothing
Readfile = strTemp
If Err.Number <> 0 Then Err.Clear
End Function
'================================================
%>
上一篇: WordPress 更新后 500 错误错误
下一篇: 电脑上网10分种自动断线的问题?
文章来自: 网络
引用通告: 查看所有引用 | 我要引用此文章
Tags: ADODB ASP FSO
相关日志:
下一篇: 电脑上网10分种自动断线的问题?
文章来自: 网络
引用通告: 查看所有引用 | 我要引用此文章
Tags: ADODB ASP FSO
相关日志:
评论: 0 | 引用: 0 | 查看次数: 7562
发表评论