473,792 Members | 2,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to loop through <configSections > elements?

I have the following sections defined in my app.config file:

<configSections >
<section name="1"
type="System.Co nfiguration.Dic tionarySectionH andler" />
<section name="2"
type="System.Co nfiguration.Dic tionarySectionH andler" />
<section name="3"
type="System.Co nfiguration.Dic tionarySectionH andler" />
</configSections>

The number of <sectionelement s is not set, but each section will contain
the same key names. I need to get a name of each section (1, 2, 3) to read
the key-value pairs for each section. I can't figure out how to loop through
<configSections elements. I would appreciate your help.
Oct 7 '08 #1
7 6225
On Tue, 07 Oct 2008 13:36:06 -0700, Eve <Ev*@discussion s.microsoft.com >
wrote:
I have the following sections defined in my app.config file:

<configSections >
<section name="1"
type="System.Co nfiguration.Dic tionarySectionH andler" />
<section name="2"
type="System.Co nfiguration.Dic tionarySectionH andler" />
<section name="3"
type="System.Co nfiguration.Dic tionarySectionH andler" />
</configSections>

The number of <sectionelement s is not set, but each section will
contain
the same key names. I need to get a name of each section (1, 2, 3) to
read
the key-value pairs for each section. I can't figure out how to loop
through
<configSections elements. I would appreciate your help.
What does the code that you are currently using to read the app.config
file look like?

It's hard to suggest an alternative or improvement on what you're doing
without actually knowing what you're doing.

Pete

Oct 7 '08 #2
I have a method that accepts a section name as a parameter and retrieves its
settings like this:

public void GetSectionSetti ngs(string sectionName)
{
IDictionary configTable = (IDictionary)Co nfigurationMana ger.GetSection
(sectionName);
string dayOrMonth = configTable["DayOrMonth "].ToString();
...
}

What I need is the code that loops through <configSections <section>
elements and passes the section name (such as "1") to GetSectionSetti ngs
method. I could not find any code on the web that would do that.
"Peter Duniho" wrote:
On Tue, 07 Oct 2008 13:36:06 -0700, Eve <Ev*@discussion s.microsoft.com >
wrote:
I have the following sections defined in my app.config file:

<configSections >
<section name="1"
type="System.Co nfiguration.Dic tionarySectionH andler" />
<section name="2"
type="System.Co nfiguration.Dic tionarySectionH andler" />
<section name="3"
type="System.Co nfiguration.Dic tionarySectionH andler" />
</configSections>

The number of <sectionelement s is not set, but each section will
contain
the same key names. I need to get a name of each section (1, 2, 3) to
read
the key-value pairs for each section. I can't figure out how to loop
through
<configSections elements. I would appreciate your help.

What does the code that you are currently using to read the app.config
file look like?

It's hard to suggest an alternative or improvement on what you're doing
without actually knowing what you're doing.

Pete

Oct 7 '08 #3
On Wed, 08 Oct 2008 06:33:02 -0700, Eve <Ev*@discussion s.microsoft.com >
wrote:
The code inside GetSectionSetti ngs method retrieves the individual
sections
named "1", "2", "3". The thing is I DO NOT KNOW the names of those
sections.
That's why I need to loop through all <sectionelement s contained within
<configSections to figure out the section name and pass it to
GetSectionSetti ngs().
Sorry, I don't know how to be more specific than that.
You can be more specific by posting the code. A concise-but-complete code
sample would unambiguously explain exactly what is going on.
Oct 8 '08 #4
Again, this is my code for GetSectionSetti ngs method that accepts a section
name as a parameter and retrieves the section's settings:
public void GetSectionSetti ngs(string sectionName)
{
IDictionary configTable = (IDictionary)Co nfigurationMana ger.GetSection
(sectionName);
string dayOrMonth = configTable["DayOrMonth "].ToString();
...
}
I DON'T have any code that loops through <sectionelement s within
<configSections because I HAVE NO CLUE HOW TO DO IT - that's why I posted my
question on this forum.

"Peter Duniho" wrote:
On Wed, 08 Oct 2008 06:33:02 -0700, Eve <Ev*@discussion s.microsoft.com >
wrote:
The code inside GetSectionSetti ngs method retrieves the individual
sections
named "1", "2", "3". The thing is I DO NOT KNOW the names of those
sections.
That's why I need to loop through all <sectionelement s contained within
<configSections to figure out the section name and pass it to
GetSectionSetti ngs().
Sorry, I don't know how to be more specific than that.

You can be more specific by posting the code. A concise-but-complete code
sample would unambiguously explain exactly what is going on.
Oct 8 '08 #5
On Wed, 08 Oct 2008 12:12:19 -0700, Eve <Ev*@discussion s.microsoft.com >
wrote:
Again, this is my code for GetSectionSetti ngs method that accepts a
section
name as a parameter and retrieves the section's settings:
>public void GetSectionSetti ngs(string sectionName)
{
IDictionary configTable = (IDictionary)Co nfigurationMana ger.GetSection
(sectionName);
string dayOrMonth = configTable["DayOrMonth "].ToString();
...
}
I don't see any way for that method to work generally. It can only work
for sections that implement the IDictionary interface, and you haven't
explained why the containing section does, never mind what type is
returned by that section.
I DON'T have any code that loops through <sectionelement s within
<configSections because I HAVE NO CLUE HOW TO DO IT - that's why I
posted my
question on this forum.
I'm not asking for the code that you can't write. But you haven't even
posted a concise-but-complete code sample of what _does_ work.

Please see http://www.yoda.arachsys.com/csharp/complete.html and
http://www.yoda.arachsys.com/csharp/incomplete.html
Oct 8 '08 #6
This is the extract from my app.config file:
<configSections >
<section name="1"
type="System.Co nfiguration.Dic tionarySectionH andler" />
<section name="2"
type="System.Co nfiguration.Dic tionarySectionH andler" />
<section name="3"
type="System.Co nfiguration.Dic tionarySectionH andler" />
</configSections>

<1>
<add key="DayOrMonth " value="M" />
<add key="NoOfDaysOr Months" value="3" />
</1>

<2>
<add key="DayOrMonth " value="M" />
<add key="NoOfDaysOr Months" value="2" />
</2>

<3>
<add key="DayOrMonth " value="D" />
<add key="NoOfDaysOr Months" value="14" />
</3>

GetSectionSetti ngs() code that I posted DOES WORK for me. I simply perform
this call:
GetSectionSetti ngs("1");
GetSectionSetti ngs("2");
GetSectionSetti ngs("3");

and the method gets values for each element in each section (M and 3 for
section "1", M and 2 for section "2", D and 14 for section "3") and does some
processing based on those values.

I don't want to hard-code "1", "2", "3" when I call GetSectionSetti ngs
because there could be 50 sections, not just 3, and I don't need my program
to know what the names of those sections are, I want the program to figure
that out by looping through <configSections elements. It shouldn't be even
necessary for me to post GetSectionSetti ngs() code because it's got NOTHING
to do with how I would loop through <configSections elements.
"Peter Duniho" wrote:
On Wed, 08 Oct 2008 12:12:19 -0700, Eve <Ev*@discussion s.microsoft.com >
wrote:
Again, this is my code for GetSectionSetti ngs method that accepts a
section
name as a parameter and retrieves the section's settings:
public void GetSectionSetti ngs(string sectionName)
{
IDictionary configTable = (IDictionary)Co nfigurationMana ger.GetSection
(sectionName);
string dayOrMonth = configTable["DayOrMonth "].ToString();
...
}

I don't see any way for that method to work generally. It can only work
for sections that implement the IDictionary interface, and you haven't
explained why the containing section does, never mind what type is
returned by that section.
I DON'T have any code that loops through <sectionelement s within
<configSections because I HAVE NO CLUE HOW TO DO IT - that's why I
posted my
question on this forum.

I'm not asking for the code that you can't write. But you haven't even
posted a concise-but-complete code sample of what _does_ work.

Please see http://www.yoda.arachsys.com/csharp/complete.html and
http://www.yoda.arachsys.com/csharp/incomplete.html
Oct 8 '08 #7
On Tue, 28 Oct 2008 10:50:01 -0700, Eve <Ev*@discussion s.microsoft.com >
wrote:
Does anyone know the answer to my question? I would expect to get some
help
from this site, but nobody provided me with the appropriate code - the
one
that I found myself is only partially working - nobody from all the
experts
knows the solution? I don't mean to sound rude, I'm just looking for
help.
Contrary to what one might think from many of the messages here, this
newsgroup is a) not populated by people who know every last thing there is
to know about .NET, and b) is not really even for .NET programming
questions.

It's specifically for questions about C#, and by implicit community
agreement, questions about .NET wind up answered as people are able too.
But when you're doing something that is outside the normal realm of
experience, it's not too surprising that no one has a direct, easy answer
to your question.

That becomes especially true when you cannot be bothered to post a
concise-but-complete code example that reliably demonstrates your
problem. People who are experienced but not experts can often help work
through a problem. But they are not likely to invest any time or effort
in doing so when the person posting the question won't do their own part.

Pete
Oct 28 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2177
by: Faisal | last post by:
I have a question regarding the "PublicKeyToken" attribute of the "<section>" tag in the web.config file. Pretty much most references have this value set to "b77a5c561934e089"; the same value as in the machine.config file <configSections <section name="sampleSection" type="System.Configuration.SingleTagSectionHandler, System,Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" / </configSections My question is, does the...
0
1742
by: anonieko | last post by:
Add a reference to log4net.dll 1: In the APP.CONFIG write the following: <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="log4net" type="System.Configuration.IgnoreSectionHandler" /> </configSections>
2
4365
by: Joseph Geretz | last post by:
Parser Error Message: Only one <configSections> element allowed. It must be the first child element of the root <configuration> element. OK, fine, easy enough to fix, I just need to copy and paste this block to where .NET wants it to be. But I can't help but think, why??? Doesn't this insistense on ordinal placement run counter to the whole XML 'philosophy'? I mean the node "/configuration/configSections" should be just as accessible...
1
2263
by: Joseph Geretz | last post by:
Why isn't the ASP.NET runtime providing a valid reference for this object to my WebService? I'm trying to use WSE and DIME to send attachments via Web Service. I've provided a whole lot of information in the thread below: DIME: Attachments.Add - Object reference not set to an instance of an object. Bu when all is said and done, the crux of the problem is that ResponseSoapContext.Current = <undefined value> when I attempt to access it....
2
5156
by: Vikram | last post by:
I am using log4net in a vb.net console application. But its not working. I have added congif setting in app.config file also No error is generated but app. does not write to log file. app.config file: <?xml version="1.0" encoding="utf-8" ?>
5
8614
by: Rainer Queck | last post by:
Hello NG, Is it possible to share the settings of an application with a class libreary? In my case I have a application and a set of different reports (home made) put into a class library. The plan is to delivere different report.dlls with the main app. But it is essentially importent, that the reports and the app use the same settings.
9
2721
by: Milsnips | last post by:
Hi all. i'm tryng to implement the Rewrite.NET url rewritining functionality into a test project i've created, however i am hitting a problem at this line (direct from the web example): System.Collections.Specialized.NameValueCollection SectionIndex = (System.Collections.Specialized.NameValueCollection)System.Configuration.ConfigurationSettings.GetConfig("Rewrite.NET/Index"); The value always returns me null, and just to check it was...
0
9518
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9033
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.