asp createTextFile生成文本文件支持utf8

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

Function createTextFile(Byval content,Byval fileDir,Byval code)
	dim fileobj,fileCode : fileDir=replace(fileDir, "\", "/")
	if isNul(code) then fileCode=Charset else fileCode=code
	call createfolder(fileDir,"filedir")
	if fileCode="utf-8" then
		on error resume next
		With objStream
			.Charset=fileCode:
			.Type=2:
			.Mode=3:
			.Open:
			.Position=0
			.WriteText content:
			.SaveToFile Server.MapPath(fileDir), 2
			.Close
		End With
	else
		on error resume next:err.clear
		set fileobj=objFso.CreateTextFile(server.mappath(fileDir),True)
		fileobj.Write(content)
		set fileobj=nothing
	end if
	if Err Then err.clear :createTextFile=false : errid=err.number:errdes=err.description:Err.Clear : echoErr err_09,errid,errdes else createTextFile=true
End Function
Sub echoErr(byval str,byval id, byval des)  

  dim errstr,cssstr
		cssstr="<meta http-equiv=""Content-Type"" content=""text/html; charset="&Charset&""" />"
  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>"
  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>"
  cssstr=""
  die(errstr)
End Sub

ASP生成UTF-8编码的代码

方法一:createtextfile生成文件方法

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

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

Set ccObjStream = Server.CreateObject("ADODB.Stream")
With ccObjStream
.Type = 2
.Mode = 3
.Open
.Charset = "utf-8"
.Position = ccObjStream.Size
.WriteText 要生成的内容
.SaveToFile 要生成文件路径和文件名,2
.Close
End With

CreateTextFile 方法
创建指定文件并返回 TextStream 对象,该对象可用于读或写创建的文件。

object.CreateTextFile(filename[, overwrite[, unicode]])

参数
object

必选项。应为 FileSystemObject 或 Folder 对象的名称。

filename

必选项。字符串表达式,指明要创建的文件。

overwrite

可选项。Boolean 值指明是否可以覆盖现有文件。如果可覆盖文件,该值为 True;如果不能覆盖文件,则该值为 False 。如果省略该值,则不能覆盖现有文件。

unicode

可选项。Boolean 值指明是否以 Unicode 或 ASCII 文件格式创建文件。如果以 Unicode 文件格式创建文件,则该值为 True;如果以 ASCII 文件格式创建文件,则该值为 False。如果省略此部分,则假定创建 ASCII 文件。

以上就是asp createTextFile生成文本文件支持utf8的详细内容,更多关于asp createTextFile的资料请关注我们其它相关文章!

(0)

相关推荐

  • asp createTextFile生成文本文件支持utf8

    但很多时候为了方便,我们会自定义生成文本文件的函数 Function createTextFile(Byval content,Byval fileDir,Byval code) dim fileobj,fileCode : fileDir=replace(fileDir, "\", "/") if isNul(code) then fileCode=Charset else fileCode=code call createfolder(fileDir,"

  • ASP中生成文本文件的两种方式

    ASP里两种常用的生成文件的方式是:利用ADODB.Stream生成文件和利用Scripting.FileSystemObject生成文件 1.Scripting.FileSystemObject生成文件方法:  复制代码 代码如下: <%  Set fso = CreateObject("Scripting.FileSystemObject")  File=Server.MapPath("要生成文件路径和文件名.htm")  Set txt=fso.Open

  • ASP+模板生成Word、Excel、html的代码第1/2页

    大多数都是采用Excel.Application(http://www.blueidea.com/tech/program/2006/3547.asp)组件来生成发现容易出错,而且对于大多数和我一样的菜鸟来说,比较麻烦,考虑到前些天用ASP+模板+adodb.stream生成静态页面的办法,经过多次尝试,终于掌握了一种用ASP+模板生成Excel和word的新的办法,先分享如下: 用模板生成Excel.Word最大优点: Word.Excel文档样式易于控制和调整,以往用Excel.Applic

  • asp定时生成静态HTML的代码

    复制代码 代码如下: <% '判断是否要生成新的HTML if Application("cache_asptohtml_date")="" then Application.Lock Application("cache_asptohtml_date")=now() Application.Unlock Call aspTohtml Response.Redirect("index.html") end if if D

  • 不用模板只用ASP+FSO生成静态HTML页的一个方法

    不用模板,只用ASP+FSO生成静态HTML页的一个方法(对于内容密集型页面特别适用)  转载请注明:转自http://goaler.xicp.net FSO生成静态HTML文件的时候替换模板标签一直是一个很麻烦的问题,至少我是这么认为的,还要别外做一个模板,麻烦!,我今天看见有一个方法可以解决这个问题 如一个正常的index.asp页面,并且用ASP代码调出数据库中的内容,另建一个makehtml.asp的页面,加入一个textarea域,假设为name="body",将index.

  • ASP.NET生成二维码的方法总结

    本文实例总结了ASP.NET生成二维码的方法.分享给大家供大家参考,具体如下: 分享一例c#生成二维码的代码,直接引用ThoughtWorks.QRCode.dll 类生成二维码,有需要的朋友参考下. 方法1.直接引用ThoughtWorks.QRCode.dll 类,生成二维码. 代码示例: ThoughtWorks.QRCode.Codec.QRCodeEncoder encoder = new QRCodeEncoder(); encoder.QRCodeEncodeMode = QRCo

  • ASP.NET生成验证码的方法

    本文实例为大家分享了ASP.NET生成验证码的具体代码,供大家参考,具体内容如下 首先,添加一个一般处理程序 注释很详细了,有不懂的欢迎评论 using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Web; using System.Web.SessionState; namespace Project_Practice { /// <summary

  • asp.net 生成静态页笔记

    1.使用serever.Excute 复制代码 代码如下: StreamWriter sw = new StreamWriter(Server.MapPath("html/Login.html"), false); Server.Execute("ShowColumn.aspx?id=1&page=2", sw); sw.Close(); 2.替换字符 url重写 1.定义重写规则 urls.xml 变成urls.config 复制代码 代码如下: <

  • SQL server不支持utf8 php却用utf8的矛盾问题解决方法

    核心代码 function convert2utf8($string) { return iconv("gbk","utf-8",$string); } function convert2gbk($string) { return iconv("utf-8","gbk",$string); } 当插入数据,或修改数据的时候,把utf-8,转为gbk,存入数据库. 当获取数据的时候,将数据转为utf-8. 这个方法在底层的数据中

  • ASP.NET生成图形验证码的方法详解

    本文实例讲述了ASP.NET生成图形验证码的方法.分享给大家供大家参考,具体如下: 通常生成一个图形验证码主要 有3个步骤: (1)随机产生一个长度为N的随机字符串,N的值可由开发可由开发人员自行设置.该字符串可以包含数字.字母等. (2)将随机生成的字符串创建成图片,并显示. (3)保存验证码. 新建一个页面为default.aspx,  放置一个TextBox控件和一个Image控件,TextBox控件用于输入生成的字符串,Image控件用于显示字符串,它的图片就为生成的图形验证码image

随机推荐