Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello. I am writing an application that has several hardcoded directory paths. I would like to write a configuration utility to write an XML based INI file. This file would be read at the execution of the program and the variables initialized. Does anyone have a link to a good reference or thread. I would really benefit from seeing some code of an actual variable being initialized with data from an external file.

 

Thanks

brazilnut

  • Leaders
Posted

Here's some old code I played around with for a while. You can probably figure out how to change it to fit your needs.

Shared Sub New()
       cnnStr = GetConfig("connectionString")
       strRootDir = GetConfig("rootDir")
       intRecentDefinition = GetConfig("recentDefinition")
       strRootWebDir = GetConfig("rootWebDir")
   End Sub

   Private Shared Function GetConfig(ByVal key As String) As String
       Try
           Dim xmlDoc As New XmlDocument()
           xmlDoc.Load("..\Config.xml")
           Return xmlDoc.SelectSingleNode("//" & key).InnerText
       Catch ex As Exception
           Throw New Exception("Error reading configuration file: Config.xml", ex)
       End Try
   End Function

--tim

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...