Click here to Skip to main content
15,907,329 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all.
I am new to c#.net.Please help me out.

I am taking data from the configuration file. it contains sections along with the parameters defined in each section.I can read the header and can put it into tree.But i am not able to get the parameters present inside each section and put inside the parent(each header).

Only for the first header i am getting the parameters, other parameters are not added to the respective headers.

here is my code:

this is for accessing headers

C#
foreach (string sectionName in sectionNames)
                {

                    if (sectionName != string.Empty)
                        treeView1.Nodes.Add(sectionName);
             

                }


this for accessing parameters present inside the header.

C#
foreach (string sectionValue in sectionValues)
                {
                   // for (int i = 0; i < sectionNames.Length; i++)
                    {
                        if (sectionValue != string.Empty)
                        {
                            treeView1.Nodes[0].Nodes.Add(sectionValue);

                        }
                    }


how to access all the parameters inside the other headers present in configuration file?
Posted

C#
System.Configuration.ConfigurationManager.GetSection("");

this code for access to the config sections.

else you can read the config as a xml file and access to the section using linq to xml!
C#
XDocument xdoc = XDocument.Load("web.config"));

this link can help you
http://broadcast.oreilly.com/2010/10/understanding-c-simple-linq-to.html[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900