ConfigurationManager.OpenExeConfiguration

 private void GetConfig()
        {
            try
            {
                string configPath = string.Format(@"{0}\{1}", _appStartPath, ConfigFile);
                Configuration config = ConfigurationManager.OpenExeConfiguration(configPath);


                txt_NoMsgInterval.Text = config.AppSettings.Settings["NoMsgInterval"].Value;
                txt_WorkThreadCount.Text = config.AppSettings.Settings["WorkThreadCount"].Value;


                txt_DbConnStr.Text = config.AppSettings.Settings["DbConnStr"].Value;


                txt_ControlSrvPort.Text = config.AppSettings.Settings["ControlSrvPort"].Value;
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
            }

        }



      private void SetConfig()
        {
            string key = "";
            string value = "";








            Configuration config = ConfigurationManager.OpenExeConfiguration(string.Format(@"{0}\{1}", _appStartPath, ConfigFile));//ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            //


            key = "NoMsgInterval";
            value = txt_NoMsgInterval.Text.Trim();
           //  ConfigurationManager.AppSettings[key] = value;
            //config.AppSettings[key] = value;
            config.AppSettings.Settings[key].Value = value;


            key = "WorkThreadCount";
            value = txt_WorkThreadCount.Text.Trim();
            config.AppSettings.Settings[key].Value = value;


            //key = "DefaultDataStoreSrvIp";
            //value = txt_DefaultDataStoreSrvIp.Text.Trim();
            // ConfigurationManager.AppSettings[key] = value;




            //key = "DefaultDataStoreSrvPort";
            //value = txt_DefaultDataStoreSrvPort.Text.Trim();
            // ConfigurationManager.AppSettings[key] = value;


            key = "DbConnStr";
            value = txt_DbConnStr.Text.Trim();
            config.AppSettings.Settings[key].Value = value;


            //key = "LogFilePath";
            //value = txt_LogFilePath.Text.Trim();
            // ConfigurationManager.AppSettings[key] = value;


            key = "ControlSrvPort";
            value = txt_ControlSrvPort.Text.Trim();
            //config.AppSettings[key] = value;


            config.AppSettings.Settings[key].Value = value;


            //ConfigurationManager
            //_acfghlp.SaveAppConfig();


             config.Save(ConfigurationSaveMode.Modified);
             ConfigurationManager.RefreshSection("appSettings");


        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值