Link to home
Start Free TrialLog in
Avatar of gromul
gromul

asked on

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.

Thanks
Avatar of surajguptha
surajguptha
Flag of United States of America image

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
Avatar of gromul
gromul

ASKER

I got it working with the following format using the code from http://www.codeproject.com/csharp/ConfigurationReader.asp:

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

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" ?>
<configuration>
   <configSections>
      <sectionGroup name="applicationSettings" type="System.Configuration.applicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a77a5c561034e089" >
         <section name="MyProject.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a77a5c561034e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
      </sectionGroup>
   </configSections>
   <applicationSettings>
      <MyProject.Properties.Settings>
         <setting name="Key1" serializeAs="String">
            <value>Value1</value>
         </setting>
      </MyProject.Properties.Settings>
   </applicationSettings>
</configuration>
ASKER CERTIFIED SOLUTION
Avatar of surajguptha
surajguptha
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial