1

I need to change the config file myApp.exe.configat runtime. How to make sure that the program would be started to work with a modified file without leaving the program?

It may be necessary to use a ConfigurationManager.

Thank you!

Muds
  • 4,006
  • 5
  • 31
  • 53
Max
  • 99
  • 1
  • 12
  • 1
    what yo want to modify in config file. If you want to edit save some app setting then you can do this. http://www.codeproject.com/Articles/14744/Read-Write-App-Config-File-with-NET – sm.abdullah May 22 '15 at 13:03
  • From what I understand, in your project, under Properties. The `Setting.settings` file can contain your application settings. These act like *default* settings, which will installed when the user runs the app. You can change and save these using the `ConfigurationManager`. – Mike Eason May 22 '15 at 13:05
  • You can modify and save user settings without restarting. You *can't* do that with application settings. What kind of setting do you want to change? – Panagiotis Kanavos May 22 '15 at 13:09
  • Not a good idea. And not possible if your application is installed to, for example, program files. There are probably better ways to accomplish your goals. You should [edit] and outline what you are trying to do. –  May 22 '15 at 14:53

1 Answers1

1

It's definitely possible, I did this at work a while back. Essentially, you can load a new app.config file into memory, then tell .NET to use the new file. From that point on, all variables in the Configurarion section change when read using the standard .NET calls.

Sorry I cant give specifics, you might have to Google some more - but at least you know its possible!!

Having said this, I believe this is the wrong architectural path to go down. Far better to store your settings in an external file in your own format. It really is a royal pain to update app.config, and if we hadnt had to do it for compatibility reasons with legacy assemblies it would not have been worth it in the least. The legacy assemblies used WCF which in itself was a mistake. WCF is a ghastly architectural morass, with few redeeming features compared to any of the modern alternatives.

Update

Community
  • 1
  • 1
Contango
  • 76,540
  • 58
  • 260
  • 305