Solved

Loop through AppSettings in VB.NET app.config

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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