关于winform中*.exe.config中的appSettings的节点的读取与修改
2015-10-22 10:38
162 查看
//读取到这个节点 string file = System.Windows.Forms.Application.ExecutablePath; Configuration config = ConfigurationManager.OpenExeConfiguration(file); string comNumber = config.AppSettings.Settings["comNumber"].Value.ToString(); comboBox1.SelectedItem = comNumber; //设置这个节点方法1,亲测可行 string file = System.Windows.Forms.Application.ExecutablePath; Configuration config = ConfigurationManager.OpenExeConfiguration(file); bool exist = false;//记录这个com端口值是否存在 if (config.AppSettings.Settings["comNumber"] != null) { exist = true; } if (exist) { config.AppSettings.Settings.Remove("comNumber"); } config.AppSettings.Settings.Add("comNumber", comNO); config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); //方法2,因为上方法可行,这个并没有测试 //Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); //config.AppSettings.Settings. //config.AppSettings.Settings.Add("comNumber", comNO); //config.Save(ConfigurationSaveMode.Full); //ConfigurationManager.RefreshSection("appSettings");
导入的是一个System.Configuration的,
同样的connectionString也是差不多的,这里没有摘录,网上都是
相关文章推荐
- Android教程 -06 Activity的生命周期
- Android教程 -06 Activity的生命周期
- [转]Android进程间通信
- iOS 状态蓝颜色设置和隐藏
- android 自定义toast 开源项目
- android 的四种枚举
- 微信:转账超两万收手续费 红包不受影响
- Unity调试函数执行时间
- WinAppDeployCmd部署Win10 App 到移动设备
- Android开发手记(14) 使用MediaPlayer播放mp3
- 剖析iOS开发中Cocos2d-x的内存管理相关操作
- android 中 任务、进程和线程的区别
- 微信付费阅读开始内测
- The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, SettingFragment, String)
- viewDidLoad, viewWillDisappear, viewWillAppear等区别及各自的加载顺序
- android Uri获取真实路径转换成File的方法
- iOS GCD多线程使用
- Android Gradle实用技巧——多渠道打包
- cocos2d-js项目发布
- [转]android ANR产生原因和解决办法