How to save custom setting in app.config?

I know that it’s nice to store configuration data in app.config (for example, database connection strings), and not hard, even if I write the application only for myself. But is there a way to update the configuration data stored in app.config from a program that uses it?

+4
source share
2 answers

If you use the settings for the project, you can mark each parameter as an application or user.

If they are configured as a user, they will be saved for each user, and when you call the Save method, it will be updated in the configuration for that user.

The draft code has a really detailed article on saving all types of settings.

+6
source

app.config is not what you want to use for user data, as it will be stored somewhere in Program Files (which the user should not have write permissions). Instead, the settings marked with a UserScopedSettingAttribute will go into the .config file with the user's area, somewhere in% LocalAppData%.

It seemed to me that the best way to find out what it is is to mess around with the "Settings" tab of Visual Studio (on the project properties pages), and then look at the code that it generates and look in% LocalAppData% to see the file, which it generates.

+1
source

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


All Articles