function loadtempletfile(byval path) on error resume next dim objstream set objstream = server.createobject("adodb.stream") with objstream .type = 2 .mode = 3 .open .loadfromfile server.mappath(path) if err.number <> 0 then err.clear response.write("预加载的模板[" & path & "]不存在!") response.end() end if .charset = "" & chrset & "" .position = 2 loadtempletfile = .readtext .close end with set objstream = nothing end function
2、用fso实现模板的加载速度快,但好多虚拟主机不提供fso功能
复制代码 代码如下:
'******************************************************************************************************* '函数名:LoadTemplate '作 用:取出模板内容 '参 数:TemplateFname模板地址 '返回值:模板内容 '******************************************************************************************************** Function LoadTemplate(TemplateFname) on error resume next Dim FSO, FileObj, FileStreamObj Set FSO = CreateObject("scripting.filesystemobject") TemplateFname = Server.MapPath(Replace(TemplateFname, "//", "/")) If FSO.FileExists(TemplateFname) = False Then LoadTemplate = "模板不存在,请先绑定!" Else Set FileObj = FSO.GetFile(TemplateFname) Set FileStreamObj = FileObj.OpenAsTextStream(1) If Not FileStreamObj.AtEndOfStream Then LoadTemplate = FileStreamObj.ReadAll Else LoadTemplate = "模板内容为空" End If End If Set FSO = Nothing:Set FileObj = Nothing:Set FileStreamObj = Nothing LoadTemplate=LoadTemplate & Published End Function '**************************************************