Solved

Loop through AppSettings in VB.NET app.config

Posted on 2011-03-17
4
1,806 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

615 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