1, the use of adodb.stream implementation of the general virtual host are provided
Copy Code code 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 ("Pre-loaded template [" & Path &] does not exist! ")
Response.End ()
End If
. CharSet = "" & Chrset & ""
. Position = 2
Loadtempletfile =. ReadText
. Close
End With
Set objstream = Nothing
End Function
2, the use of FSO to achieve template loading speed, but a lot of virtual host does not provide FSO function
Copy Code code as follows:
'*******************************************************************************************************
' Function name: loadtemplate
' Function: Remove template contents
' 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 = "Template does not exist, please bind first!"
Else
Set fileobj = FSO. GetFile (Templatefname)
Set filestreamobj = Fileobj.openastextstream (1)
If not Filestreamobj.atendofstream Then
LoadTemplate = Filestreamobj.readall
Else
loadtemplate = "Template content is empty"
End If
End If
Set FSO = Nothing:set Fileobj = Nothing:set Filestreamobj = Nothing
Loadtemplate=loadtemplate & Published
End Function
'**************************************************
ASP reads the code for the template using the FSO
3, there is another way to put the template in the database (slow)