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 @   BicycleBoy  阅读(278)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示