一个ASP创建文本文件的函数

作者:网络 来源:佚名 更新时间:2009-02-14 00:59:28 点击:
 '=============================================================
 '过程名:createdtextfile
 '作  用:创建文本文件
 '参  数:filename  ----文件名
 '        body  ----主要内容
 '=============================================================
 public function createdtextfile(byval filename,byval body)
  on error resume next
  dim f,sname
  filename = replace(replace(filename, "/", "\"), "\\", "\")
  if instr(filename, ":") = 0 then filename = server.mappath(filename)
  sname=mid(filename,instrrev(filename,"\")+1,len(filename))
  if instr(sname,".")=0 then filename = filename &"\index.html"
  if mainsetting(7)="0" then
   set f = fso.createtextfile(filename,true, false)
   f.write body
   f.close
   set f = nothing
  else
   if mainsetting(7)="2" then
    newaspstream.charset="utf-8"
   elseif mainsetting(7)="3" then
    newaspstream.charset="big5"
   else
    newaspstream.charset="gb2312"
   end if
   newaspstream.type = 2'设置内容为文本
   newaspstream.mode = 3'设置为可读可写
   newaspstream.open()
   newaspstream.writetext(body)
   newaspstream.savetofile filename,2
   newaspstream.flush
   newaspstream.close()
  end if
  if err.number <> 0 then err.clear
 end function