来源 更改配置app.Config里的值

[ 2009-11-17 17:53:37 | 作者: 一线风 | 阅读:966 | 评论:0 | 天气: rain | 心情: normal ]
Font Size: Large | Medium | Small
C#代码
  1.  System.Configuration.Configuration config =   
  2.      ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);   
  3.   
  4.  AppSettingsSection appSetcion = config.GetSection("appSettings"as AppSettingsSection;   
  5.  appSetcion.Settings["AutoRun"].Value = "this is  a test";   
  6.   
  7. // ConfigurationManager.AppSettings["Save"] = isCheck.ToString();   
  8.  txtMessage.Text += ConfigurationManager.AppSettings["AutoRun"];   
  9.  config.Save();   
更改自动定义配置的C#代码
  1. bool isCheck = chkAutoRun.Checked;   
  2.             System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);   
  3.             CoreSection core = config.GetSection("coreSection"as CoreSection;   
  4.             if (core != null) core.AutoRun = isCheck;   
  5.             config.Save();  

 

注意:要使用Section操作才行。直接用Appsettting["somekey"]是不行的

[一线风 最后修改于 2009-11-17 18:00:01]
分类:工作相关
Tag: C# 配置