C#读取配置文件

来源:互联网 发布:门牙里的超级味 知乎 编辑:程序博客网 时间:2024/05/14 13:38

配置文件是项目中不可缺少的,我们在开发系统时要善于运用配置文件配置数据去使系统更好的适用于多种情况。

public string getValuefromXml(string key)

{

    XmlDocument doc = new XmlDocument();

    string XmlPath = AppDomain.CurrentDomain.BaseDirectory+@"Flex\bin\conf\config.xml";

    doc.Load(XmlPath );

    String value;
            XmlNodeList nodes = doc.GetElementsByTagName(key);          
            if (nodes.Count == 1)
            {
                value = nodes[0].InnerText;
            }
            else
            {
                throw new Exception("读取配置文件出错");
            }
            return value;
        }

}

0 0
原创粉丝点击