C#中读取和更改APP.config配置文件?
配置文件如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connection>
<add name="ServerName" connectionString=".\sql2000" />
<add name="DataBaseName" connectionString="pubs"/>
<add name="UserID" connectionString="sa"/>
<add name="PassWord" connectionString=""/>
</connection>
</configuration>
怎样读取和更改这个配置文件?
------解决方案--------------------获取
string ServerName= ConfigurationManager.ConnectionStrings["ServerName"].ConnectionString;//ServerName== add节点的name
其他同理
------解决方案--------------------
或者操作xml来获取和修改
/// <summary>
/// 获取指定节点下面对应属性的值
/// </summary>
/// <param name="strFileName">文件路径</param>
/// <param name="nodeName">节点名称</param>
/// <param name="nodeDir">指定节点所在的节点目录</param>
/// <param name="attribute">节点对应的属性名称</param>
/// <returns></returns>
public static string GetNodeValue(string strFileName, string nodeName, string nodeDir, string attribute)
{
string value = null;
try
{
XmlDocument xmlDoc = new XmlDocument();