ASCII码 ASCII码

asp createTextFile生成文本文件支持utf8

发布于:2022-05-04 01:32:57  栏目:技术文档

一般情况下可以使用fso的createTextFile函数,但有时候我们需要生成utf8格式的文件,那么就可以用下面的函数扩展了

但很多时候为了方便,我们会自定义生成文本文件的函数

  1. Function createTextFile(Byval content,Byval fileDir,Byval code)
  2. dim fileobj,fileCode : fileDir=replace(fileDir, "\", "/")
  3. if isNul(code) then fileCode=Charset else fileCode=code
  4. call createfolder(fileDir,"filedir")
  5. if fileCode="utf-8" then
  6. on error resume next
  7. With objStream
  8. .Charset=fileCode:
  9. .Type=2:
  10. .Mode=3:
  11. .Open:
  12. .Position=0
  13. .WriteText content:
  14. .SaveToFile Server.MapPath(fileDir), 2
  15. .Close
  16. End With
  17. else
  18. on error resume next:err.clear
  19. set fileobj=objFso.CreateTextFile(server.mappath(fileDir),True)
  20. fileobj.Write(content)
  21. set fileobj=nothing
  22. end if
  23. if Err Then err.clear :createTextFile=false : errid=err.number:errdes=err.description:Err.Clear : echoErr err_09,errid,errdes else createTextFile=true
  24. End Function
  25. Sub echoErr(byval str,byval id, byval des)
  26. dim errstr,cssstr
  27. cssstr="<meta http-equiv=""Content-Type"" content=""text/html; charset="&Charset&""" />"
  28. cssstr=cssstr&"<style>body{text-align:center}#msg{background-color:white;border:1px solid #0073B0;margin:0 auto;width:400px;text-align:left}.msgtitle{padding:3px 3px;color:white;font-weight:700;line-height:28px;height30px;font-size:12px;border-bottom:1px solid #0073B0; text-indent:3px; background-color:#0073B0}#msgbody{font-size:12px;padding:20px 8px 30px;line-height:25px}#msgbottom{text-align:center;height:20px;line-height:20px;font-size:12px;background-color:#0073B0;color:#FFFFFF}</style>"
  29. errstr=cssstr&"<script language=""javascript"">setTimeout(""goLastPage()"",5000);function goLastPage(){location.href='"& sitePath &"/';}</script><div id='msg'><div class='msgtitle'>提示:【"&str&"】</div><div id='msgbody'>错误号:"&id&"<br>错误描述:"&des&"<br /><a href=""javascript:history.go(-1);" rel="external nofollow" ">返回上一页</a>&nbsp;<a href=""" rel="external nofollow" & sitePath &"/"">返回首页</a></div><div id='msgbottom'>Powered by AspCms2.0</div></div>"
  30. cssstr=""
  31. die(errstr)
  32. End Sub
  33. Function createFolder(Byval dir,Byval dirType)
  34. dim subPathArray,lenSubPathArray, pathDeep, i
  35. on error resume next
  36. dir=replace(dir, "\", "/")
  37. if trim(sitePath) = "" then pathDeep = "/" else pathDeep = sitePath
  38. pathDeep = server.MapPath(pathDeep)
  39. dir=replace(server.mappath(dir), pathDeep, "")
  40. subPathArray=split(dir, "\")
  41. select case dirType
  42. case "filedir"
  43. lenSubPathArray=ubound(subPathArray) - 1
  44. case "folderdir"
  45. lenSubPathArray=ubound(subPathArray)
  46. end select
  47. for i=0 to lenSubPathArray
  48. if trim(subPathArray(i)) <> "" then
  49. pathDeep=pathDeep&"\"&subPathArray(i)
  50. if not objFso.FolderExists(pathDeep) then objFso.CreateFolder pathDeep
  51. end if
  52. next
  53. if Err Then createFolder=false : errid=err.number:errdes=err.description:Err.Clear : echoErr err_10,errid,errdes else createFolder=true
  54. End Function
  55. 使用方法

createTextFile content,htmlfilepath,””

content就是内容,filepath就是文件路径http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E7%94%B5%E8%AF%9D%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%BC%80%E6%88%B7%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E4%BC%9A%E5%91%98%E5%BC%80%E6%88%B7%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%BC%80%E6%88%B7%E5%BE%AE%E4%BF%A1%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%BC%80%E6%88%B7%E7%BB%8F%E7%90%86%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%BC%80%E6%88%B7%E7%94%B5%E8%AF%9D%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%BC%80%E6%88%B7%E8%81%94%E7%B3%BB%E6%96%B9%E5%BC%8F%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%9C%A8%E7%BA%BF%E5%BC%80%E6%88%B7%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%BC%80%E6%88%B7%E8%81%94%E7%B3%BB%E7%94%B5%E8%AF%9D%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%BC%80%E6%88%B7%E6%B3%A8%E5%86%8C%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%BC%80%E6%88%B7%E5%92%A8%E8%AF%A2%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%BC%80%E6%88%B7%E4%B8%AD%E5%BF%83%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%BC%80%E6%88%B7%E7%83%AD%E7%BA%BF%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%BC%80%E6%88%B7%E7%83%AD%E7%BA%BF%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%AE%A2%E6%9C%8D%E5%92%A8%E8%AF%A2%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%AE%A2%E6%9C%8D%E7%83%AD%E7%BA%BF%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%AE%A2%E6%9C%8D%E4%B8%AD%E5%BF%83%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%9C%A8%E7%BA%BF%E5%AE%A2%E6%9C%8D%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%AE%A2%E6%9C%8D%E7%94%B5%E8%AF%9D%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%AE%A2%E6%9C%8D%E5%BE%AE%E4%BF%A1%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%AE%A2%E6%9C%8D%E8%81%94%E7%B3%BB%E7%94%B5%E8%AF%9D%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E5%AE%A2%E6%9C%8D%E8%81%94%E7%B3%BB%E6%96%B9%E5%BC%8F%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E7%8E%B0%E5%9C%BA%E5%AE%A2%E6%9C%8D%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E6%B3%A8%E5%86%8C%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E6%B3%A8%E5%86%8C%E8%B4%A6%E5%8F%B7%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E7%83%AD%E7%BA%BF%E7%94%B5%E8%AF%9D%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%85%AC%E5%8F%B8%E6%B8%B8%E6%88%8F%E7%BD%91%E5%9D%80%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E4%B8%8A%E4%B8%8B%E5%88%86%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E4%B8%8A%E4%B8%8B%E5%88%86%E5%AE%A2%E6%9C%8D%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E4%B8%8A%E4%B8%8B%E5%88%86%E8%81%94%E7%B3%BB%E6%96%B9%E5%BC%8Fkka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E4%B8%8A%E4%B8%8B%E5%88%86%E7%83%AD%E7%BA%BF%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E4%B8%8A%E4%B8%8B%E5%88%86%E5%92%A8%E8%AF%A2%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E4%B8%8A%E4%B8%8B%E5%88%86%E7%94%B5%E8%AF%9D%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E8%81%94%E7%B3%BB%E6%96%B9%E5%BC%8F%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E7%94%B5%E8%AF%9D%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E5%BC%80%E6%88%B7%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E5%BC%80%E6%88%B7%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E5%BC%80%E6%88%B7%E5%AE%A2%E6%9C%8D%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E5%BC%80%E6%88%B7%E7%BB%8F%E7%90%86%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E5%BC%80%E6%88%B7%E7%94%B5%E8%AF%9D%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E5%BC%80%E6%88%B7%E8%81%94%E7%B3%BB%E6%96%B9%E5%BC%8F%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E5%9C%A8%E7%BA%BF%E5%BC%80%E6%88%B7%E5%BE%AE%E4%BF%A1ccv5670http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E5%BC%80%E6%88%B7%E8%81%94%E7%B3%BB%E7%94%B5%E8%AF%9D%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E6%B3%A8%E5%86%8C%E5%BC%80%E6%88%B7%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E5%BC%80%E6%88%B7%E6%B3%A8%E5%86%8C%E5%BE%AE%E4%BF%A1kka10011http://www.hnxxrsj.gov.cn/Error.aspx?msg=%E5%8D%8E%E7%BA%B3%E5%A8%B1%E4%B9%90%E5%BC%80%E6%88%B7%E4%B8%AD%E5%BF%83%E5%BE%AE%E4%BF%A1kka10011

createTextFile “内容”,”/article/11/22/3.htm”,””

ASP生成UTF-8编码的代码

方法一:createtextfile生成文件方法

  1. function WriteToFile(FileName,FileContent)
  2. set fso=server.createobject("scripting.filesystemobject")
  3. set fp=fso.createtextfile(server.mappath(FileName),,True)
  4. fp.write(FileContent)
  5. end function

方法二:ADODB.Stream生成文件方法 支持utf8,最上面的函数就包括下面的两种方法

.Type = 2.Mode = 3.Open.Charset = “utf-8”.Position = ccObjStream.Size.WriteText 要生成的内容.SaveToFile 要生成文件路径和文件名,2.CloseEnd With```

相关推荐
阅读 +