asp.net读取并修改指定config文件

读取:

            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();
            }

posted @ 2013-05-17 16:08  BicycleBoy  阅读(274)  评论(0编辑  收藏  举报