读取配置:


    DStxtReadConfig.Text = ConfigurationManager.ConnectionStrings["bjxingchConnection"].ConnectionString.ToString();


设置配置信息:


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

                            config.ConnectionStrings.ConnectionStrings["bjxingchConnection"].ConnectionString = DStxtSaveConfig.Text;

    config.Save(ConfigurationSaveMode.Modified);

    ConfigurationManager.RefreshSection("connectionStrings");



    ConfigurationManager.RefreshSection("connectionStrings");  立即更新该节点,如果不使用这句话更新将在程序下次启动时更新


设置appSettings设置:

Configuration config = ConfigurationManager.OpenExeConfiguration(Assembly.GetEntryAssembly().Location);
AppSettingsSection sec = (AppSettingsSection)config.AppSettings;
sec.Settings["IP"].Value = "192.168.1.1";
config.Save();
ConfigurationManager.RefreshSection("appSettings");