[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 777
  • Last Modified:

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
0
gromul
Asked:
gromul
  • 3
1 Solution
 
surajgupthaCommented:
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?
0
 
surajgupthaCommented:
U can use the above solution if u were not particular with using only the SETTINGS file
0
 
gromulAuthor Commented:
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>
0
 
surajgupthaCommented:
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.
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.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now