views:

792

answers:

2

I have a C# .NET Console application exe with an app.config specifying a handful of ApplicationSettings used as parameters.

I have an additional separate (Windows Forms) exe (residing in the same directory) to allow the ApplicationSettings used by the first exe to be modified by the user.

What it the cleanest way to go about modifying the first exe's app.config from the second exe?

Thanks.

+1  A: 

you can use

public static Configuration OpenExeConfiguration(
    string exePath
)

MSDN Link

ArsenMkrt
Thanks. Will this allow me to edit the applicationSettings in the app.config, and if so how? I thought applicationSettings were considered 'readonly'..
TonE
Yeah, cfg.AppSettings should work and allow you to change settings. Try it, I can't right now.
Michał Chaniewski
No there are not readonly as I know, just use GetSection function to extract and change section you want, see samples in a given link...
ArsenMkrt
Thanks, that works fine. I was getting confused with 'AppSettings' and 'ApplicationSettings' sections of the App.Config file.
TonE
+1  A: 

Use:

Configuration cfg = ConfigurationManager.OpenExeConfiguration(path_to_exe_file_of_second_app);
// do whatever you need with that configuration
cfg.Save();

Please note that OpenExeConfiguration method takes a path to the second app exe file, not the config file itself.

Michał Chaniewski