【C#】系統配置文件的讀寫

需要添加引用,System.Configuration;


寫系統配置文件:

                Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);


                if (addrService != "")
                {
                    cfa.AppSettings.Settings["WebServiceUrl"].Value = addrService;
                }
                if (setLogin != "")
                {
                    cfa.AppSettings.Settings["LoginServerUrl"].Value = setLogin;
                }
                if (mapPath != "")
                {
                    cfa.AppSettings.Settings["InitMapPath"].Value = mapPath;
                }


                cfa.Save(ConfigurationSaveMode.Modified);
                //重新加載配置文件
                ConfigurationManager.RefreshSection("appSettings");        

讀:

                string value = ConfigurationSettings.AppSettings["InitMapPath"];





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章