ASP根据模板生成HTML静态文件类

上传人:平*** 文档编号:14310237 上传时间:2017-11-01 格式:DOCX 页数:4 大小:15.52KB
返回 下载 相关 举报
ASP根据模板生成HTML静态文件类_第1页
第1页 / 共4页
ASP根据模板生成HTML静态文件类_第2页
第2页 / 共4页
ASP根据模板生成HTML静态文件类_第3页
第3页 / 共4页
ASP根据模板生成HTML静态文件类_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《ASP根据模板生成HTML静态文件类》由会员分享,可在线阅读,更多相关《ASP根据模板生成HTML静态文件类(4页珍藏版)》请在金锄头文库上搜索。

1、ASP 根据模板生成 HTML 静态文件类) tpl.setNotes = array(替换内容) tpl.setStoreF = ./html/ 使用自动生成文件名时请在未尾加 / tpl.exeTpl Set tpl = Nothing-Class templatePrivate objFsoPrivate strFileCode 读取模板文件的内容Private intRnd 生成随机数,组合成新文件名Private tplpath 模板名称Private StorePath 生成文件存放目录Private StoreFname 生成文件名称Private arrTags 标签数组Pri

2、vate arrNotes 内容 在使用 Set 创建对象时自动执行Private Sub Class_Initialize()set objFso = CreateObject(scripting.filesystemobject)End Sub 模板文件位置+ 名称 只写Public Property Let setTplPath(ByVal tName)tplpath = Server.MapPath(Replace(tName,/,/)End Property 存储文件位置+ 名称 只写Public Property Let setStoreF(ByVal tName)tName =

3、Replace(tName,/,/) 取文件名dim arrY arrY = split(tName,/)StoreFname = Ubound(arrY)StoreFname = arrY(StoreFname) 取目录名StorePath = Replace(tName,StoreFname,)StorePath = Server.MapPath(StorePath)End Property 标签 只写Public Property Let setTags(ByVal strString)arrTags = strStringEnd Property 内容 只写Public Propert

4、y Let setNotes(ByVal strString)arrNotes = strStringEnd Property 生成在 Min 与 Max 之间取随机数Private Sub rnd_Integer(Min,Max)RandomizeintRnd = CInt(Max-Min+1)*Rnd()+Min)End Sub 生成文件名:时间+ 随机数Private Sub makeFilenamedim fnamefname = now()fname = replace(fname,-,)fname = replace(fname, ,)fname = replace(fname,:

5、,)fname = replace(fname,PM,)fname = replace(fname,AM,)fname = replace(fname,上午,)fname = replace(fname,下午,)call rnd_Integer(0,9999)StoreFname = fname&intRnd&.htmlfname = nullEnd Sub 读取模板文件内容Private Sub LoadTemplateIf objFso.FileExists(tplpath) ThenSet FileObj = objFso.GetFile(tplpath)Set FileStreamOb

6、j = FileObj.OpenAsTextStream(1)If Not FileStreamObj.AtEndOfStream ThenstrFileCode = FileStreamObj.ReadAllElse Message 1002End IfElseMessage 1001End IfSet FileObj = Nothing:Set FileStreamObj = NothingEnd Sub 更新页面内容Private Sub updateNotesif IsArray(arrNotes) and IsArray(arrTags) thenif Ubound(arrNotes

7、) = Ubound(arrTags) thenLoadTemplateFor intI = Lbound(arrNotes) to Ubound(arrNotes)strFileCode = Replace(strFileCode,arrTags(intI),arrNotes(intI)NextelseMessage 1004end ifelseMessage 1004end ifEnd Sub 创建文件夹Private Sub makeFold(ByVal strFoladName)on error resume next判断文件夹是否存在, (about files:objFso.Fil

8、eExists)If false = objFso.FolderExists(strFoladName) ThenobjFso.CreateFolder(strFoladName)if err0 thenerr.clearMessage 1003end ifEnd IfEnd Sub 创建文件Private Sub makeFiledim arrX,intI,strWstrW = arrX = split(StorePath,/) 判断目录是否存在,决定是否创建目录For intI = Lbound(arrX) to Ubound(arrX)makeFold strW&arrX(intI)st

9、rW = strW&arrX(intI)Next 未设置文件名则使用日期加随机数作为文件名if StoreFname = thenmakeFilenameend if 更新内容updateNotes 生成文件 object.CreateTextFile(filename, overwrite, unicode)Set objFout = objFso.CreateTextFile(StorePath&/&StoreFname,true) 输入内容objFout.WriteLine strFileCodeobjFout.closeset objFso = Nothing 提示操作成功Messag

10、e 1000End Sub 执行public Sub exeTplmakeFileEnd Sub 返回Private Sub Message(ByVal s)Select Case sCase 1000Response.Write 操作成功!&StoreFnameCase 1001Response.Write 模板不存在,请先绑定!Case 1002Response.Write 模板内容为空!Case 1003Response.Write 文件目录创建失败!Case ElseEnd SelectEnd Sub在使用 Set 释放对象时自动执行Private Sub Class_TerminateSet objFso = NothingEnd Sub End Class%

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号