110,534
社区成员
发帖
与我相关
我的任务
分享
XmlDocument document= new XmlDocument();
document.Load("App.config文件路径和文件名");
string NetSelect_Value = document.SelectSingleNode(@"//appSettings/add[@key=""NetSelect""]").Attributes["value"].Value;
public static string GetWebConfigParam(string ns_xpath, string name)
{
string basedir = System.AppDomain.CurrentDomain.BaseDirectory;
if (!basedir.EndsWith("\\"))
basedir += "\\";
string basefile += "Web.config";
if(!System.IO.File.Exists(basefile)) basefile = "";
if (basefile != "")
{
try
{
string webconfigfile = basefile;
if (System.IO.File.Exists(webconfigfile))
{
System.Xml.XmlDocument webconfigdoc = new System.Xml.XmlDocument();
webconfigdoc.Load(webconfigfile);
System.Xml.XmlNamespaceManager m = new System.Xml.XmlNamespaceManager(webconfigdoc.NameTable);
m.AddNamespace("ns", "http://schemas.microsoft.com/.NetConfiguration/v2.0");
System.Xml.XmlElement el = (System.Xml.XmlElement)webconfigdoc.SelectSingleNode(ns_xpath, m);
if (name == null || name.Trim() == "")
return el.InnerText;
else
{
name = name.Trim();
if (el.HasAttribute(name))
return el.GetAttribute(name);
}
}
}
catch
{
}
}
return "";
}