XML文件简单操作
1读取XML文件
using System.Xml;
public static string GetAppSetting(string appSettingName)
{
XmlDocument _settings = new XmlDocument();
string FileName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\我的应用程序.exe.config";
StreamReader _sr = new StreamReader(FileName);
_settings.Load(_sr);
_sr.Close();
foreach (XmlNode node in _settings["configuration"]["appSettings"])
{
if (string.Compare(appSettingName, node.Attributes["key"].Value) == 0)
{
return node.Attributes["value"].Value;
}
}
return "";
}