ConfigurationManager - how to read/write into a custom section?
-
My config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration><appSettings>
<add key="sunshine" value="125" />
<add key="moonshine" value="50" />
<add key="seashine" value="10" />
</appSettings><Settings2>
<add key="persistent" value="0" />
<add key="smooth" value="1" />
</Settings2></configuration>
I can read/write settings into <appSettings> but don´t know how can i read/write from <Settings2> .... and if i can create new sections like <SettingsN> ... I´m using System.Configuration but only could read/write into the default section named <appSettings>... perhaps someone can give me a hand or point me to the right direction, thanks in advance.
-
My config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration><appSettings>
<add key="sunshine" value="125" />
<add key="moonshine" value="50" />
<add key="seashine" value="10" />
</appSettings><Settings2>
<add key="persistent" value="0" />
<add key="smooth" value="1" />
</Settings2></configuration>
I can read/write settings into <appSettings> but don´t know how can i read/write from <Settings2> .... and if i can create new sections like <SettingsN> ... I´m using System.Configuration but only could read/write into the default section named <appSettings>... perhaps someone can give me a hand or point me to the right direction, thanks in advance.
Zeokat wrote:
I´m using System.Configuration but only could read/write into the default section named ...
System.Configuration only exposes methods which for the predefined section (i.e. appsettings). For your purpose, you should rather consider it as a normal xml file and do the read/write.
Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
Zeokat wrote:
I´m using System.Configuration but only could read/write into the default section named ...
System.Configuration only exposes methods which for the predefined section (i.e. appsettings). For your purpose, you should rather consider it as a normal xml file and do the read/write.
Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
My config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration><appSettings>
<add key="sunshine" value="125" />
<add key="moonshine" value="50" />
<add key="seashine" value="10" />
</appSettings><Settings2>
<add key="persistent" value="0" />
<add key="smooth" value="1" />
</Settings2></configuration>
I can read/write settings into <appSettings> but don´t know how can i read/write from <Settings2> .... and if i can create new sections like <SettingsN> ... I´m using System.Configuration but only could read/write into the default section named <appSettings>... perhaps someone can give me a hand or point me to the right direction, thanks in advance.
As modifying configuration files directly can be very dangerous. You should also take a look at How to: Create Custom Configuration Sections[^]. There are also loads of articles, which you might find easier to understand. Just Google for Custom Configuration Section
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
As modifying configuration files directly can be very dangerous. You should also take a look at How to: Create Custom Configuration Sections[^]. There are also loads of articles, which you might find easier to understand. Just Google for Custom Configuration Section
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”