Summary of several methods for loading templates in asp

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.