how to access app.config sectionGroup/sections

B

Bill McCormick

Hello,

How can one access sectionGroup/sections (iterate or LINQ query) in app.config?

<configuration>
<configSections>
<sectionGroup name="groups">
<section name="group1"
type="System.Configuration.SingleTagSectionHandler"/>
<section name="group2"
type="System.Configuration.SingleTagSectionHandler"/>
</sectionGroup>
</configSections>

<groups>
<group1 value1="value11" value2="value12" value3="value13" />
<group2 value1="value21" value2="value22" value3="value23" />
</groups>

</configuration>

So far I have the following:

System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

foreach (ConfigurationSection group in
config.SectionGroups["groups"].Sections) {

//what field (collection?) in group contains the value1-3 values?

}



TIA Bill
 
B

Bill McCormick

Hello,

How can one access sectionGroup/sections (iterate or LINQ query) in
app.config?

<configuration>
<configSections>
<sectionGroup name="groups">
<section name="group1"
type="System.Configuration.SingleTagSectionHandler"/>
<section name="group2"
type="System.Configuration.SingleTagSectionHandler"/>
</sectionGroup>
</configSections>

<groups>
<group1 value1="value11" value2="value12" value3="value13" />
<group2 value1="value21" value2="value22" value3="value23" />
</groups>

</configuration>

So far I have the following:

System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

foreach (ConfigurationSection group in
config.SectionGroups["groups"].Sections) {

//what field (collection?) in group contains the value1-3 values?

}
Just trying to to this very simple:

Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

ConfigurationSection group = config.GetSection("groups/group1");

so then, I would like to be able to do something like this:

string myval = group["value1"];

but no; no dice.

Help!!!
 
B

Bill McCormick

Hello,

How can one access sectionGroup/sections (iterate or LINQ query) in
app.config?

<configuration>
<configSections>
<sectionGroup name="groups">
<section name="group1"
type="System.Configuration.SingleTagSectionHandler"/>
<section name="group2"
type="System.Configuration.SingleTagSectionHandler"/>
</sectionGroup>
</configSections>

<groups>
<group1 value1="value11" value2="value12" value3="value13" />
<group2 value1="value21" value2="value22" value3="value23" />
</groups>

</configuration>

So far I have the following:

System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

foreach (ConfigurationSection group in
config.SectionGroups["groups"].Sections) {

//what field (collection?) in group contains the value1-3 values?

}
Just trying to to this very simple:

Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

ConfigurationSection group = config.GetSection("groups/group1");

so then, I would like to be able to do something like this:

string myval = group["value1"];

but no; no dice.

Help!!!

After hours of trial, error and googling - I found this:

http://devlicio.us/blogs/derik_whit...config-and-custom-configuration-sections.aspx

Somebody else was kind enough to blog about it - after many hours of trial,
error and googling. Turns out my latest incarnation, with a
CustomConfiguration class is pretty close.

Happy coding :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top