asp新建文本文件并写入内容

Function BuildFile(ByVal sFile, ByVal sContent)
  On Error Resume Next
  Dim oFSO, oStream
 ' Response.Write sFile
 ' Response.Write sContent
 ' Response.end
  If CacheConfig(24) = "1" Then
   '如果选用ADODB.Steam 则强制转换成Unicode
   If Right(LCase(sFile),4) <> ".xml" Then
    sContent = AnsiToUnicode(sContent)
   End if
   Set oStream = Server.CreateObject(CacheCompont(2))
   With oStream
    .Type = 2
    .Mode = 3
    .open
    '.Charset = "utf-8"
    .Charset = "gb2312"
    .Position = oStream.size
    .WriteText = sContent
    .SaveToFile sFile, 2
    .Close
   End With
   Set oStream = Nothing
  Else
   Set oFSO = Server.CreateObject(CacheCompont(1))
   Set oStream = oFSO.CreateTextFile(sFile,True)
   oStream.Write sContent
   oStream.Close
   '增加对特殊字符的保护,强制将内容转换成Unicode
   If Err.Number<>0 Then
    sContent = AnsiToUnicode(sContent)
    Set oStream = Server.CreateObject(CacheCompont(2))
    With oStream
     .Type = 2
     .Mode = 3
     .open
     '.Charset = "utf-8"
     .Charset = "gb2312"
     .Position = oStream.size
     .WriteText = sContent
     .SaveToFile sFile, 2
     .Close
    End With
    Err.Clear
   End If
   Set oStream = Nothing
   Set oFSO = Nothing
  End If
 End Function

上一篇: asp验证Email输入正确性函数
下一篇: asp提取媒体文件并清理播放器代码
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: asp
相关日志:
评论: 0 | 引用: 0 | 查看次数: 3599
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭

 广告位

↑返回顶部↑