Custom settings in App.config

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

I would like to store some nodes & child nodes in the app.config file and
was wondering if there is a way to read these values in as a config file
rather than an xml.

Thanks,
Joe
 
Hi Joe,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to read the settings in
app.config file as a configuration file instead of an xml file. If there is
any misunderstanding, please feel free to let me know.

You can try to use System.Configuration.AppSettingsReader or
System.Configuration.ConfigurationSettings class to do this. The
ConfigurationSettings.AppSettings property contains a name/value collection
of the keys in your app.config file. Also please check the following link
for more information.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vboriintroductiontoapplicationsettingstorage.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hey Joe

Put the following segment into the <configuration> tag of the app.config:

<appSettings>
<add key="SomeConf" value="SomeValue" />
</appSettings>

And into your CS file:

string someVar = ConfigurationSettings.AppSettings[ "SomeConf" ];
 
Thanks but what I was looking for is something more like:

<MyCustomSettings>
<setting1 name="s1" color="green" width="400"/>
<setting2 name="s2" color="white" width="200"/>
</MyCustomSettings>

-Joe
 
Hi Joe,

In the App.config file, you have to put your settings in the format
specified. Or you'll not able to get the setting using
ConfigurationSettings.AppSettings.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top