How to get app.config of another application and change it

I have a windows application. e.g. FormA and FormB

The app.config file of form A is below

<?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> 

Now I have another application called Form B.

I want to get both the binding settings and the connection strings of form A to form B.

Next, I should be able to change both of these settings and connection strings and save them in form A.

I know how to extract application settings and connection strings of the same application and change.

But how can I get some other application and change it.

Please let me know.

In fact, I have 4 service windows running under the same setup., One web service and one wcf service and one application. They all have different app.configs, consisting of different sets of settings and different connection strings. I have to create a windows application that will retrieve each of these parameters and then save it accordingly.

I tried to this level

 ExeConfigurationFileMap filename= new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = @"D:\Home\FormA\FormA\bin\Debug\FormA.exe.config"; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(filename, ConfigurationUserLevel.None); 

But then it just hit, I just don’t know how to proceed further (Sounds silly!)

Can someone help me go the way.

Relationship cmrhema

+4
source share
2 answers
  ExeConfigurationFileMap fileMap2 = new ExeConfigurationFileMap(); fileMap2.ExeConfigFilename = @"OtherFile"; Configuration config2 = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); ConnectionStringSettings newSettings = config.ConnectionStrings.ConnectionStrings["oldSConString"]; ConnectionStringsSection csSection = config2.ConnectionStrings; csSection.ConnectionStrings.Add(newSettings); config2.Save(ConfigurationSaveMode.Modified); 

VS2005 C # Programmatically change the connection string contained in app.config

+1
source

Basically, you need to open the configuration for this other executable like this:

 // full path to other EXE, including EXE extension - but *NOT* .config !! string otherExePath = @"C:\........\OtherApp\bin\Debug\OtherApp.exe"; Configuration otherConfig = ConfigurationManager.OpenExeConfiguration(otherExePath); 

and then you can access all the settings of the new otherConfig configuration:

 string otherSetting = otherConfig.AppSettings.Settings["TestSetting1"].Value; 

and you can also save it back (provided that you have the necessary permissions for this directory).

 otherConfig.Save(): 
+2
source

Source: https://habr.com/ru/post/1301365/


All Articles