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
Thanks
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
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 .applicati onSettings Group, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a77a5c56103 4e089" >
<section name="MyProject.Properties .Settings" type="System.Configuration .ClientSet tingsSecti on, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a77a5c56103 4e089" allowExeDefinition="Machin eToLocalUs er" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<MyProject.Properties.Sett ings>
<setting name="Key1" serializeAs="String">
<value>Value1</value>
</setting>
</MyProject.Properties.Set tings>
</applicationSettings>
</configuration>
<?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"
<section name="MyProject.Properties
</sectionGroup>
</configSections>
<applicationSettings>
<MyProject.Properties.Sett
<setting name="Key1" serializeAs="String">
<value>Value1</value>
</setting>
</MyProject.Properties.Set
</applicationSettings>
</configuration>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.