Solved

Loop through AppSettings in VB.NET app.config

Posted on 2011-03-17
4
1,743 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 75

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 75

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 75

Expert Comment

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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

786 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