Link to home
Start Free TrialLog in
Avatar of Jon Winterburn
Jon WinterburnFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Loop through AppSettings in VB.NET app.config

Hi experts,

I have a number of settings in app.config which I wish to loop through and read their values into my Windows Service.  However, I am unable to get this to work - what am I doing wrong?

Thanks

Jon
Protected Overrides Sub OnStart(ByVal args() As String)
        For Each sp As Configuration.SettingsPropertyValue In My.Settings.Properties
            myWatch = New System.IO.FileSystemWatcher(strServer & sp.ToString, "*.*")
            AddHandler myWatch.Created, AddressOf Me.RunMySub
            myWatch.IncludeSubdirectories = False
            myWatch.EnableRaisingEvents = True
        Next
End Sub

 <applicationSettings>
        <MyApp.My.MySettings>
            <setting name="Path01" serializeAs="String">
                <value>The value I want number 1</value>
            </setting>
            <setting name="Path02" serializeAs="String">
                <value>The value I want number 2</value>
            </setting>
           <setting name="Path03" serializeAs="String">
                <value>The value I want number 3</value>
            </setting>
       </MyApp.My.MySettings>
    </applicationSettings>

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

Try this modification:
For Each sp As Configuration.SettingsProperty In My.Settings.Properties

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jon Winterburn

ASKER

Excellent, thanks! I knew I was close.
NP. Glad to help  = )