Read settings file into NameValueCollection

Is there a way to read settings from a .settings file into NameValueCollection without having to parse XML? I know about Properties for the current application, but that doesn't apply in this case since I need something where I could specify the settings file anywhere on the disk and get the settings.

Who is Participating?
There is no straight or easy way a simple name value collection can represent a multi level deep hierrarchial file with your custom sections. For that you will have to write a class similar to the file, read the values into the properties.
Have you thought about creating a custom object and serializing it into a XML file so as to get the basic skeleton needed and then adding on to it and using a deserializer to convert it back to the custom class?
U can use the above solution if u were not particular with using only the SETTINGS file
gromulAuthor Commented:
I got it working with the following format using the code from

<?xml version="1.0" encoding="utf-8" ?>
      <add key="Key1" value="Value1" />

However this is not exactly what I wanted, as I know have to maintain my own config files in addition to the settings file already there.

I would appreciate any hints in what I would need to do to process a file like this:

<?xml version="1.0" encoding="utf-8" ?>
      <sectionGroup name="applicationSettings" type="System.Configuration.applicationSettingsGroup, System, Version=, Culture=neutral, PublicKeyToken=a77a5c561034e089" >
         <section name="MyProject.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=, Culture=neutral, PublicKeyToken=a77a5c561034e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
         <setting name="Key1" serializeAs="String">
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.