1. General Virtual Hosts implemented using adodb. stream provide
Copy codeThe Code is as follows: 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 ("the preloaded template [" & path & "] does not exist! ")
Response. end ()
End if
. Charset = "" & chrset &""
. Position = 2
Loadtempletfile =. readtext
. Close
End
Set objstream = nothing
End function
2. fast template loading using fso, but many virtual hosts do not provide the fso FunctionCopy codeThe Code is as follows: '*************************************** **************************************** ************************
'Function name: LoadTemplate
'Usage: retrieve template content
'Parameter: TemplateFname template address
'Return value: Template content
'*************************************** **************************************** *************************
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 = "the template does not exist. Please bind it first! "
Else
Set FileObj = FSO. GetFile (TemplateFname)
Set FileStreamObj = FileObj. OpenAsTextStream (1)
If Not FileStreamObj. AtEndOfStream Then
LoadTemplate = FileStreamObj. ReadAll
Else
LoadTemplate = "the template content is blank"
End If
End If
Set FSO = Nothing: Set FileObj = Nothing: Set FileStreamObj = Nothing
LoadTemplate = LoadTemplate & Published
End Function
'*************************************** ***********
ASP uses FSO to read the template code
3. Another method is to put the template in the database (slow speed)