zoukankan      html  css  js  c++  java
  • Winform修改配置文件节点保存到配置文件

    主要使用:

    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);//将当前应用程序的配置文件作为 System.Configuration.Configuration 对象打开。

    config.Save();//刷新命名节,这样在下次检索它时将从磁盘重新读取它。

    ConfigurationManager.RefreshSection("appSettings");//刷新命名节,这样在下次检索它时将从磁盘重新读取它。

     示例:

    配置节点方法:

            /// <summary>
            /// 修改配置文件 节点值,保存并刷新
            /// </summary>
            public void SaveSettiongs(params string[] str)
            {
                if (XtraMessageBox.Show("是否保存修改?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.None, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);//将当前应用程序的配置文件作为 System.Configuration.Configuration 对象打开。
                    config.AppSettings.Settings["PathOne"].Value = str[0];
                    config.AppSettings.Settings["PathTwo"].Value = str[1];
                    config.AppSettings.Settings["PathThr"].Value = str[2];
                    config.Save();//刷新命名节,这样在下次检索它时将从磁盘重新读取它。
                    ConfigurationManager.RefreshSection("appSettings");//刷新命名节,这样在下次检索它时将从磁盘重新读取它。
                    XtraMessageBox.Show("已保存修改");
                }
            }

    保存按钮:

                SaveSettiongs(this.txtExcelPath.Text, this.txtStart.Text, this.txtEnd.Text);
           this.Close();

    加载事件:

            private void FormPath_Load(object sender, EventArgs e)
            {
                this.txtPathOne.Text = ConfigurationManager.AppSettings["PathOne"].ToString();
                this.txtPathTwo.Text = ConfigurationManager.AppSettings["PathTwo"].ToString();
                this.txtPathThr.Text = ConfigurationManager.AppSettings["PathThr"].ToString();
            }

    配置文件:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
      </startup>
    
      <appSettings>
        <add key="PathOne" value="D:PathOne"/>
        <add key="PathTwo" value="D:PathTwo"/>
        <add key="PathThr" value="D:PathThr"/>
      </appSettings>
    </configuration>
  • 相关阅读:
    SharePoint 2013中的Index Partition的一个小问题
    SharePoint 2013中, 默认Index文件的位置
    Visual Studio Test Project的一个小问题
    HyperV最佳实践
    测试环境中的一个HyperV的选项设置
    什么是SharePoint 2013中的Shredded Storage?
    SharePoint的数据库性能需要注意的一点
    记录HyperV中挪动虚拟机的一次实践
    SharePoint 2013上一台机器可以有多个Crawl Component么?
    SharePoint Client Object Model的一个小例子
  • 原文地址:https://www.cnblogs.com/xifengyeluo/p/8276118.html
Copyright © 2011-2022 走看看