Revit二次开发之简单的读写配置文件App.config内的值

版本:

VS2015 .net 4.5.2

Revit2018

实现:

使用C#语言进行配置文件的读取和修改。

下面展示关键代码:

App.config



  
    
    
    
    
  

cs

            string assmblyPath = this.GetType().Assembly.Location;
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            config = ConfigurationManager.OpenExeConfiguration(assmblyPath);

            string Height0 = config.AppSettings.Settings["AAA"].Value;
            string Angle0 = config.AppSettings.Settings["BBB"].Value;

            #region 修改节点Value
            config.AppSettings.Settings["AAA"].Value = getNewHeight;
            config.AppSettings.Settings["BBB"].Value = getNewAngle;
            config.Save(ConfigurationSaveMode.Modified);
            //刷新,否则程序读取的还是之前的值(可能已装入内存)
            System.Configuration.ConfigurationManager.RefreshSection("appSettings");
            #endregion

 

你可能感兴趣的:(Revit二次开发,配置文件)