Re: multiple same section in app.config
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 14 Sep 2006 11:45:22 -0400
Droopy,
The reason this doesn't work is that you are trying to create something
of a heiarchical nature for data that is simply a set of pairs.
If you want to use the NameValueSectionHandler, then you need to do
something like this:
<Connections>
<add key="ComPort_1" value="COM2" />
<add key="Name_1" value="Connection 1" />
<add key="ComPort_2" value="COM4" />
<add key="Name_2" value="Connection 2" />
</Connections>
Then, you would have to parse the names to see how the values are
grouped together.
If you want to have a different kind of config setup, then you will have
to create your own custom handler.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Droopy" <droopytoonnospam@xxxxxxxxxxx> wrote in message
news:Xns983EB244CE24Fdroopytoonnospamhotm@xxxxxxxxxxxxxxxxx
Hi,
I would like to configure some device connections through app.config.
I created the following config file but it fails because I have the same
section more than once :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="Connections">
<section name="Connection"
type="System.Configuration.NameValueSectionHandler" />
</sectionGroup>
</configSections>
<Connections>
<Connection>
<add key="ComPort" value="COM2" />
<add key="Name" value="Connection 1" />
<add key="ID" value="1" />
</Connection>
<Connection>
<add key="ComPort" value="COM4" />
<add key="Name" value="Connection 2" />
<add key="ID" value="2" />
</Connection>
</Connections>
</configuration>
I have 2 questions :
1) How should I modify this configuration file ?
2) Now that ConfigurationSettings.GetConfig is obsolete, is does not
seems clear for me how to use ConfigurationManager to read the config
file.
Thanks in advance,
Droopy.
.
- Follow-Ups:
- Re: multiple same section in app.config
- From: Droopy
- Re: multiple same section in app.config
- References:
- multiple same section in app.config
- From: Droopy
- multiple same section in app.config
- Prev by Date: Re: multiple same section in app.config
- Next by Date: Re: Exception in test cases
- Previous by thread: Re: multiple same section in app.config
- Next by thread: Re: multiple same section in app.config
- Index(es):
Relevant Pages
|