ConfigWeb_Read

Reads a key value from certain section in Web.config
Originally from http://tech.genericwhite.com/access-web-dot-config-from-classic-asp

CodeFunctionName
What is this?

Public

Not Tested

Imported
'****************************** ConfigWeb_Read *******************************
' Purpose:        Utility function to get value from a configuration file.
' Conditions:    CONFIG_FILE_PATH must be refer to a valid XML file
' Input:            sectionName - a section in the file, eg, appSettings
'                        attrName - refers to the "key" attribute of an entry
' Output:        A string containing the value of the appropriate entry
'**********************************************************************************

CONFIG_FILE_PATH="Web.config" 'if no qualifier, refers to this directory. can point elsewhere.
Function ConfigWeb_Read(sectionName, attrName)
    Dim oXML, oNode, oChild, oAttr, dsn
    Set oXML=Server.CreateObject("Microsoft.XMLDOM")
    oXML.Async = "false"
    oXML.Load(Server.MapPath(CONFIG_FILE_PATH))
    Set oNode = oXML.GetElementsByTagName(sectionName).Item(0)
    Set oChild = oNode.GetElementsByTagName("add")
    ' Get the first match
    For Each oAttr in oChild
        If oAttr.getAttribute("key") = attrName then
            dsn = oAttr.getAttribute("value")
            ConfigWeb_Read = dsn
            Exit Function
        End If
    Next
End Function

sectionName, attrName

settingValue = ConfigWeb_Read ("appSettings", "someKeyName")
Response.Write(settingValue)

Views 3,334

Downloads 1,252

CodeID
DB ID