国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

asp createTextFile生成文本文件支持utf8

瀏覽:83日期:2022-06-04 17:17:03

但很多時候為了方便,我們會自定義生成文本文件的函數(shù)

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
Function createFolder(Byval dir,Byval dirType)
dim subPathArray,lenSubPathArray, pathDeep, i
on error resume next
dir=replace(dir, "\", "/")
  if trim(sitePath) = "" then pathDeep = "/" else pathDeep = sitePath
  pathDeep = server.MapPath(pathDeep)
dir=replace(server.mappath(dir), pathDeep, "")
subPathArray=split(dir, "\")
select case dirType
case "filedir"
 lenSubPathArray=ubound(subPathArray) - 1
case "folderdir"
lenSubPathArray=ubound(subPathArray)
end select
for i=0 to lenSubPathArray
    if trim(subPathArray(i)) <> "" then
  pathDeep=pathDeep&"\"&subPathArray(i)
  if not objFso.FolderExists(pathDeep) then objFso.CreateFolder pathDeep
    end if
next
if Err Then createFolder=false : errid=err.number:errdes=err.description:Err.Clear : echoErr err_10,errid,errdes else createFolder=true
End Function

使用方法

createTextFile content,htmlfilepath,""

content就是內(nèi)容,filepath就是文件路徑

createTextFile "內(nèi)容","/article/11/22/3.htm",""

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,最上面的函數(shù)就包括下面的兩種方法

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

CreateTextFile 方法
創(chuàng)建指定文件并返回 TextStream 對象,該對象可用于讀或?qū)憚?chuàng)建的文件。

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

參數(shù)
object

必選項。應(yīng)為 FileSystemObject 或 Folder 對象的名稱。

filename

必選項。字符串表達式,指明要創(chuàng)建的文件。

overwrite

可選項。Boolean 值指明是否可以覆蓋現(xiàn)有文件。如果可覆蓋文件,該值為 True;如果不能覆蓋文件,則該值為 False 。如果省略該值,則不能覆蓋現(xiàn)有文件。

unicode

可選項。Boolean 值指明是否以 Unicode 或 ASCII 文件格式創(chuàng)建文件。如果以 Unicode 文件格式創(chuàng)建文件,則該值為 True;如果以 ASCII 文件格式創(chuàng)建文件,則該值為 False。如果省略此部分,則假定創(chuàng)建 ASCII 文件。 

以上就是asp createTextFile生成文本文件支持utf8的詳細內(nèi)容,更多關(guān)于asp createTextFile的資料請關(guān)注其它相關(guān)文章!

標(biāo)簽: ASP
相關(guān)文章:
主站蜘蛛池模板: 99视频在线看观免费 | 亚洲国产午夜精品理论片的软件 | fc2ppv在线播放 | 久久se精品一区精品二区 | 久久精品国产影库免费看 | 国产日韩精品一区二区三区 | 亚洲精品成人久久久影院 | 久热国产视频 | 国产在线观看一区二区三区四区 | 国内精品免费一区二区三区 | 成人看片黄a毛片 | 成人a大片高清在线观看 | chinese耄耋70老太性 | 在线观看一区二区三区四区 | 一级毛片一级毛片a毛片欧美 | 中文字幕精品在线观看 | 国产午夜一级淫片 | 日韩中文字幕一在线 | 欧美黄色网络 | 国产成人在线综合 | 亚洲综合视频在线观看 | 亚洲综合99 | 日韩一级特黄毛片在线看 | 日本在线不卡免 | 91精品国产美女福到在线不卡 | 国产免费一区不卡在线 | 国产成人综合自拍 | 成年人色网站 | 欧美精品a毛片免费观看 | 久久精品男人的天堂 | 亚洲在线中文字幕 | 国产亚洲精品午夜高清影院 | 成人国产精品免费视频不卡 | 亚洲国产精品一区二区久 | 神马午夜-午夜片 | 操她视频网站 | 日韩精品视频一区二区三区 | 老司机亚洲精品影院在线 | 久久国产精品免费看 | 国产精品嘿咻嘿咻在线播放 | 鲁丝片一区二区三区免费 |