Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / June 2007

Tip: Looking for answers? Try searching our database.

foreach in a .settings file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carlos Sosa Albert - 12 Jun 2007 19:12 GMT
Hi guys,

Is there a way to use a foreach (C#) to go through a settings file like
this?

I can't find a collection in MyProject.MyConfigurationFile.settings.xxx, I
cant only access the settings refering like
MyProject.MyConfigurationFile.settings.Default.key1,
MyProject.MyConfigurationFile.settings.Default.key2, etc.

Thanks a lot!!!

settings file:
_______________________________________________
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile
xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings"
CurrentProfile="(Default)" GeneratedClassNamespace="CoachLibrary"
GeneratedClassName="InitialConfiguration">
 <Profiles />
 <Settings>
   <Setting Name="key1" Type="System.String" Scope="Application">
     <Value Profile="(Default)">abc</Value>
   </Setting>
   <Setting Name="key2" Type="System.String" Scope="Application">
     <Value Profile="(Default)">xyz</Value>
   </Setting>
 </Settings>
</SettingsFile>
Bob Powell [MVP] - 14 Jun 2007 18:23 GMT
Open the file in an XmlDocument and walk the list of nodes in the doc?

Use XPath to to a Select on the nodes and a for-each to step through the
ones you get back?

Signature

Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

> Hi guys,
>
[quoted text clipped - 25 lines]
>  </Settings>
> </SettingsFile>
geoffrey.munday@gmail.com - 14 Jun 2007 19:47 GMT
My first thought was what Bob suggested but you can try something like
the following as well (I'm not expressing any warranties with this
approach, you will need to tweak it and see what works for you).

           foreach (System.Configuration.SettingsProperty property in
MyProjectNamespace.Properties.Settings.Default.Properties)
           {
               switch (property.Name)
               {
                   case "key1":
                       string key1 = (string)property.DefaultValue;
                       //use key1
                       break;
                   case "key2":
                       string key2 = (string)property.DefaultValue;
                       //use key2
                       break;
               }
           }

Good luck!
-Geoff

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.