GetConfigValue

Read settings from Web.config file (or other XML files)

Originally from http://tech.genericwhite.com/access-web-dot-config-from-classic-asp

'****************************** GetConfigValue *******************************
' 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 GetConfigValue(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")
GetConfigValue = dsn
Exit Function
End If
Next
End Function

ectionName, attrName

settingValue = GetConfigValue(&#34;appSettings&#34;, &#34;someKeyName&#34;)<br/>Response.Write(settingValue)

Views 696 Downloads 312

'Web.config', 'xml', 'read', 'file', 'NotMyWork', 'settings'

ANmarAmdeen
333
Sessions Classic ASP
Revisions

v1.0