关于asp的fso的一个错误!

| |
[不指定 2007/05/03 17:48 | by Else ]
引用
Microsoft VBScript 运行时错误 错误 '800a0005'
无效的过程调用或参数

在来看我们的代码
引用
If Body<>"" Then
Set Fso = Server.CreateObject("Scripting.FileSystemObject")
Set Fout = Fso.CreateTextFile(Server.Mappath(""&Filename&""))
Fout.Write(Body)' 当编码是utf-8的时候,就会提示这里错误!
Fout.Close

解决方法
引用
If Body<>"" Then
Set Fso = Server.CreateObject("Scripting.FileSystemObject")
Set Fout = Fso.CreateTextFile(Server.Mappath(""&Filename&""),true,true)
Fout.Write(Body)'这下不会提示错出!
Fout.Close


1、FSO读取文本文件的函数!


<%
Function   prtFiles(mPath,   fName,fPath)
mPath指定相对路径
fName指定文件名(含扩展名)
fPath指定目录
Dim   fs2,   f2
Set   fs2=Server.CreateObject("Scripting.FileSystemObject")
fPath   =   Server.MapPath(mPath)&amp;   "\"  
fPath   =   fPath   &amp;   fName
Set   f2   =   fs2.OpenTextFile(fPath,1,true)
prtFiles   =   f2.ReadAll
Set   fs2   =   Nothing
End   Function
%>
比如我要输出当前目录的上级目录INC目录下的222.js文件的内容,那么asp就写成
Response.write(prtFiles("../inc","222.js",""))

2、用ADODB.Stream读取文本文件

文件内容读取.
Function LoadFile(ByVal File)
     Dim objStream
     On Error Resume Next
     Set objStream = Server.CreateObject("ADODB.Stream")
     If Err.Number=-2147221005 Then
         Response.Write " 非常遗憾,您的主机不支持ADODB.Stream,不能使用本程序"
         Err.Clear
         Response.End
     End If
     With objStream
         .Type = 2
         .Mode = 3
         .Open
         .LoadFromFile Server.MapPath(File)
         If Err.Number<>0 Then
     Response.Write " 文件"&File&"无法被打开,请检查是否存在!"
     Err.Clear
     Response.End
         End If
         .Charset = "GB2312"
         .Position = 2
         LoadFile = .ReadText
         .Close
     End With
     Set objStream = Nothing
End Function


'存储内容到文件
Sub SaveToFile(ByVal strBody,ByVal File)
     Dim objStream
     On Error Resume Next
     Set objStream = Server.CreateObject("ADODB.Stream")
     If Err.Number=-2147221005 Then
         Response.Write "
非常遗憾,您的主机不支持ADODB.Stream,不能使用本程序
"
         Err.Clear
         Response.End
     End If
     With objStream
         .Type = 2
         .Open
         .Charset = "GB2312"
         .Position = objStream.Size
         .WriteText = strBody
         .SaveToFile Server.MapPath(File),2
         .Close
     End With
     Set objStream = Nothing
End Sub

作者:Else 's Blog
地址:http://www.aixq.com/post/688/
版权所有。转载时必须链接形式注明作者和原始出处及本声明!
  • 中查看更多“关于asp的fso的一个错误!”相关内容
  • 中查看更多“关于asp的fso的一个错误!”相关内容
  • 中查看更多“关于asp的fso的一个错误!”相关内容
  • 中查看更多“关于asp的fso的一个错误!”相关内容
  • 中查看更多“关于asp的fso的一个错误!”相关内容
  • 中查看更多“关于asp的fso的一个错误!”相关内容

  • 最后编辑: Else 编辑于2008/02/03 11:34
    代码 程序 编程 | 评论(0) | 引用(0) | 阅读(2797)
    发表评论
    表情
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    打开HTML
    打开UBB
    打开表情
    隐藏
    昵称   密码   游客无需密码
    网址   电邮   [注册]
                   

    验证码 不区分大小写