配置文件是项目中不可缺少的,我们在开发系统时要善于运用配置文件配置数据去使系统更好的适用于多种情况。
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;
}
}