ConfigWeb_Read

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


'****************************** 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 (&#34;appSettings&#34;, &#34;someKeyName&#34;)<br/>Response.Write(settingValue)

Views 142 Downloads 57

'CONFIG_FILE_PATH', 'Config', 'web', 'read', 'value', 'setting', 'session', 'key', 'attrname', 'section', 'NotMyWork', 'NotTested'

ANmarAmdeen
313
Components Classic ASP
Revisions

v1.0