Evaldas Grigaitis
Evaldas Grigaitis

Reputation: 77

How to open app.config in windows forms?

I need to open app.config with a click of a button. I've been trying to find how to do this with no luck. How can I open the file itself so I could edit it?

Upvotes: 2

Views: 1830

Answers (1)

Thorsten Dittmar
Thorsten Dittmar

Reputation: 56697

If you need to open the application configuration file itself you're doing something wrong.

If you need to access settings defined using Visual Studio's settings designer, use the automatic properties like

var value = Properties.Settings.Default.SettingName;

If you want to edit user settings, do the same thing and save:

Properties.Settings.Default.SettingName = Value;
Properties.Settings.Default.Save();

You can not modify application settings anyway. If the application is installed in Program Files you will not even be allowed to write the file back, as the Program Files folder is not writable to your application.

If the application is installed using ClickOnce you're also out of luck, as the settings file for user settings is named totally differently and is not even in the same location as your application's executable.

So this comes down to: Do it right and keep your hands off app.config!

Upvotes: 4

Related Questions