C# 如何获取不同应用程序的app.config并对其进行修改

C# 如何获取不同应用程序的app.config并对其进行修改,c#,asp.net-3.5,C#,Asp.net 3.5,我有两个windows应用程序。例如,FormA和FormB FormA的app.config如下所示 <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="company" value="DSRC"/> </appSettings> <connectionStrings> <add

我有两个windows应用程序。例如,FormA和FormB

FormA的app.config如下所示

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <appSettings>

    <add key="company" value="DSRC"/>

    </appSettings>

<connectionStrings>

<add name="test" connectionString="Testing Connection String"/>

</connectionStrings>

</configuration>
但后来被击中了,我只是不知道如何继续下去(听起来很愚蠢!)

有人能帮我走下去吗

问候 cmrhema


基本上,您需要打开其他可执行文件的配置,如下所示:

// full path to other EXE, including EXE extension - but *NOT* .config !!
string otherExePath = @"C:\........\OtherApp\bin\Debug\OtherApp.exe";
Configuration otherConfig = 
              ConfigurationManager.OpenExeConfiguration(otherExePath);
然后,您可以访问新的
otherConfig
配置上的所有设置:

string otherSetting = otherConfig.AppSettings.Settings["TestSetting1"].Value;
您还可以将其保存回去(前提是您对该目录具有必要的权限)


这不会从其他应用程序获取用户设置
// full path to other EXE, including EXE extension - but *NOT* .config !!
string otherExePath = @"C:\........\OtherApp\bin\Debug\OtherApp.exe";
Configuration otherConfig = 
              ConfigurationManager.OpenExeConfiguration(otherExePath);
string otherSetting = otherConfig.AppSettings.Settings["TestSetting1"].Value;
otherConfig.Save():