Solved

Loop through AppSettings in VB.NET app.config

Posted on 2011-03-17
4
1,711 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:Jon Winterburn
  • 3
4 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 35157284
Try this modification:
For Each sp As Configuration.SettingsProperty In My.Settings.Properties

Open in new window

0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35157294
Forgot a piece:
For Each sp As Configuration.SettingsProperty In My.Settings.Properties
    myWatch = New System.IO.FileSystemWatcher(strServer & sp.DefaultValue.ToString(), "*.*")

Open in new window

0
 
LVL 11

Author Closing Comment

by:Jon Winterburn
ID: 35157735
Excellent, thanks! I knew I was close.
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 35159781
NP. Glad to help  = )
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now