版本:
VS2015 .net 4.5.2
Revit2018
实现:
使用C#语言进行配置文件的读取和修改。
下面展示关键代码:
App.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="AAA" value="500" />
<add key="BBB" value="90" />
<add key="CCC" value="500" />
<add key="DDD" value="90" />
</appSettings>
</configuration>
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