读取:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@ConfigurationManager.AppSettings["SitePath"] + "iwms.config");
XmlNodeList ndlist = xmlDoc.getElementsByTagName_r("mssql");
string temp = string.Empty;
foreach (XmlNode xl in ndlist)
{
temp = "server=" + xl.ChildNodes[0].InnerText + ";uid=" + xl.ChildNodes[2].InnerText + ";pwd=" + xl.ChildNodes[3].InnerText + ";database=" + xl.ChildNodes[1].InnerText;
}
connectionString = temp;
修改节点:
if (ConfigurationManager.AppSettings["SitePath"].ToString() == "")
{
Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);//操作appSettings
AppSettingsSection appseting = (AppSettingsSection)config.GetSection("appSettings");
appseting.Settings["SitePath"].Value = Server.MapPath("~");
config.Save();
}