今天在生成一栏目文章时出现了以下错误
Microsoft VBScript 运行时错误
错误 '800a0005'
无效的过程调用或参数
../../KS_Cls/KS.RCls.asp,行 201
为什么会出现这样的错误我不清楚,相关代码是
Sub FSOSaveFile(Content, LocalFileName)
Dim FSO, FileObj
Set FSO = Server.CreateObject(KS.Setting(99))
Set FileObj = FSO.CreateTextFile(Server.MapPath(LocalFileName), True) '创建文件
FileObj.Write Content '此语句出现了错误
FileObj.Close '释放对象
Set FileObj = Nothing:Set FSO = Nothing
End Sub
我的修改方案是
Sub FSOSaveFile(Content, LocalFileName)
Dim FSO, FileObj
Set FSO = Server.CreateObject(KS.Setting(99))
Set FileObj = FSO.CreateTextFile(Server.MapPath(LocalFileName), True) '创建文件
On Error Resume Next
FileObj.Write Content
FileObj.Close '释放对象
if err.number <> 0 then
call adoSaveFile(Content, LocalFileName)
end if
Set FileObj = Nothing:Set FSO = Nothing
End Sub
public Sub adoSaveFile(Content,LocalFileName) '新增加的使用AdodbStream生成的函数
Dim AdodbStreamObj
Set AdodbStreamObj = Server.CreateObject("Adodb.Stream")
With AdodbStreamObj
.Type = 2
.Open
.Charset = "GB2312"
.WriteText Content
.SaveToFile Server.MapPath(LocalFileName),2
.Cancel()
.Close()
End With
Set AdodbStreamObj = Nothing
End Sub
以上代码已通过测试,写出来跟大家分享下