Custom values in app.config

  • Thread starter Thread starter MS Newsgroups
  • Start date Start date
M

MS Newsgroups

Hi,

I am building an appliaction that will do some processing on specified
databases. I would like to specify in a configuration file what databases to
process.There is not a fixed number of databases so the number can vary.

Ideal (If i just could figure out how to do this) would be if i could get a
string array containing my values from the configuration file that I could
loop through.

Any suggestions on how to do this ?

Regards

Niclas Lindblom
 
Add a new item to your component and select "Application configuration".
Edit this file so it looks like

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Database1" value="my first database"/>
<add key="Database2" value="my second database"/>
<add key="SomeOtherSetting" value="my other stuff"/>
</appSettings>
</configuration>

Add these imports

Imports System.Configuration
Imports System.Collections.Specialized

And use code like this

Dim sDatabaseCollection As NameValueCollection =
ConfigurationSettings.AppSettings()

Dim sDatabase As String
For Each sDatabase In sDatabaseCollection.AllKeys
If sDatabase.StartsWith("Database") Then
MessageBox.Show(sDatabaseCollection(sDatabase))
End If
Next
 
Back
Top