asp下用實現模板載入的的幾種方法總結[原創]_應用技巧

來源:互聯網
上載者:User
1、使用adodb.stream實現的 一般虛擬機器主機都提供
複製代碼 代碼如下:

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
'**************************************************

ASP使用FSO讀模數板的代碼
3、還有一種就是把模板放到資料庫中(速度慢)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.