我需要从配置文件中获取数据并放入树形视图中 [英] I need to take data from the configuration file and put into the treeview

查看:63
本文介绍了我需要从配置文件中获取数据并放入树形视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.
我是c#.net的新手,请帮助我.

我正在从配置文件中获取数据.它包含各节以及在每个节中定义的参数.我可以读取标头并将其放入树中.但是我无法获取每个节中存在的参数并放入父级(每个标头)中.

仅对于第一个标头,我获取了参数,其他参数未添加到相应的标头中.

这是我的代码:

这是用于访问标头

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

foreach (string sectionName in sectionNames)
                {

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

                }



用于访问标头中存在的参数.



this for accessing parameters present inside the header.

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?

推荐答案

请参阅链接.
http://support.microsoft.com/kb/815786 http://www.ajaxline.com/node/258 http://www.devasp.net/net/articles/display/679.html


http://www.dreamincode.net/forums/topic/38180 -read-config-file-in-class-library/
Please refer the links.. its easy..

http://support.microsoft.com/kb/815786

http://www.ajaxline.com/node/258


http://www.devasp.net/net/articles/display/679.html


http://www.dreamincode.net/forums/topic/38180-read-config-file-in-class-library/


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


此代码可访问配置部分.

否则,您可以将配置读取为xml文件,并使用linq到xml来访问该部分!


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!

XDocument xdoc = XDocument.Load("web.config"));


此链接可以帮助您
http://broadcast.oreilly.com/2010/10/understanding-c- simple-linq-to.html [ ^ ]


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


这篇关于我需要从配置文件中获取数据并放入树形视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆