有谁知道在2005 的winapp程序App.config自定义一个节点格式?以及如何读取?搜遍csdn的帖子和baidu未发现可用的,都不适合,听说2005得用属性配置,到底该如何做呢?
我希望读取方式是这样的:
NameValueCollection col = (NameValueCollection)ConfigurationManager.GetSection("MyConfig");string myServer=col["Server"];
string myUser=col["User"];在App.config中如何配置节点?仿照webService生成的格式配置了个,但是总取得null,请大虾指点,闷了三天了,所有地方都馊了,就是没馊到... ...
我希望读取方式是这样的:
NameValueCollection col = (NameValueCollection)ConfigurationManager.GetSection("MyConfig");string myServer=col["Server"];
string myUser=col["User"];在App.config中如何配置节点?仿照webService生成的格式配置了个,但是总取得null,请大虾指点,闷了三天了,所有地方都馊了,就是没馊到... ...
<appSettings>
<add key="MyServer" value="localhost" />
<add key="Myuser" value="sa" />
</appSettings>
</configuration>
system.configation下面
<configSections>
<section name="S" type="System.Configuration.NameValueSectionHandler"/>
</configSections>
<S>
<add key="v" value="1"/>
</S>
</configuration>NameValueCollection col = (NameValueCollection)ConfigurationManager.GetSection("S");
<!--
注意: 除了手动编辑此文件以外,您还可以使用
Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
“网站”->“Asp.Net 配置”选项。
设置和注释的完整列表在
machine.config.comments 中,该文件通常位于
\Windows\Microsoft.Net\Framework\v2.x\Config 中
-->
<configuration>
<appSettings>
<add key="ServerName" value="192.168.0.85" /> <!--数据库服务器地址192.168.0.85-->
<add key="DataBase" value="puer" /> <!--数据库名称-->
<add key="UserID" value="sa" /> <!--数据库用户-->
<add key="Password" value="sa" /> <!--数据库用户密码-->
</appSettings>
<connectionStrings/>
<system.web>
result = "data source = "
+ System.Configuration.ConfigurationManager.AppSettings["ServerName"]
+ ";initial catalog = "
+ System.Configuration.ConfigurationManager.AppSettings["DataBase"]
+ ";user id = "
+ System.Configuration.ConfigurationManager.AppSettings["UserID"]
+ ";password = "
+ System.Configuration.ConfigurationManager.AppSettings["Password"]
+ ";persist security info = True";
在“VS2005“ 的“winapp程序App.config““自定义一个节点“我希望读取方式是这样的:
NameValueCollection col = (NameValueCollection)ConfigurationManager.GetSection("MyConfig");string myServer=col["Server"];
string myUser=col["User"];
“在App.config中如何配置节点?“
昂得死蛋?好多人不是针对我的问题回答耶,还是感谢关注!!
http://www.cnblogs.com/sunrack/articles/350345.html
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="Test3" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<Test3>
<add key="Hello" value="World" />
</Test3>
</configuration>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
调用部分的代码:
(需要
using System.Configuration; // 引用前需要添加此dll的引用
using System.Collections.Specialized;
)
—————————————————————————————————
//访问配置节Test3
NameValueCollection nc = (NameValueCollection)ConfigurationSettings.GetConfig("Test3");
MessageBox.Show(nc.AllKeys[0].ToString() + " " + nc["Hello"]); //输出Hello World