The .NET configuration settings feature is not as flexible as we would like. If I understand the Application Settings correctly, I am limited when I can change / edit the settings. In C #, application settings are divided into two different types or areas ("Application" and "User"), but both have limitations on how they can be changed or changed. The following table shows the difference:
SCOPE: | EDIT AT DESIGN-TIME: | EDIT AT RUN-TIME: | EDIT BETWEEN SESSIONS:
-------------------------------------------------- -------------------------------------
User | Setings.settings | Settings.Default.Save () | * Not supported *
Application | Setings.settings | * Not supported * | edit app.exe.config
Are there any “built-in” settings that will allow me to edit the settings with all three mechanisms? One of the main reasons for using the configuration file is to allow users to change the default values without having to re-create the source code (as can be done with the settings of the application area). However, the user should not force the .config file to be edited; they should also be able to make changes at runtime, which is saved in the settings (how this can be done with user-specific settings). Of course, there must be some kind of mechanism that provides both functions.
BOTTOM LINE: Why can't I change the application settings ( app.exe.config ) at runtime? That would solve all my problems. I understand that this can cause problems for users who use the same machine. But who does this?
POTENTIAL LATEST: Is there a way to change the default repository location for a user settings configuration file in a non-hidden folder?
UPDATE (for clarification): I want to say that I want to change the default setting at Development time , at Run time, or between sessions (i.e. by editing the configuration file). But when using the built-in C # saving mechanisms provided by Settings.settings , I have to choose no more than 2 out of 3. Am I missing something? Is there any other alternative that I don't know about?
[ Use case: I want to keep the default database name for the connection string, but I want the user to be able to specify a different database at run time (and thereby become the "new" default value for this user). But I also want to be able to overwrite the default value in the configuration file without restarting or re-creating the application.]
[ BEST usage example: (in response to comments)
I have a computational model with a configuration file that contains the default values for the parameters in the model. User A runs the model and decides to change the value of several parameters. This change should be saved for all future sessions for this user (i.e. Edit at RTunTime). Subsequently, this user wants to share this modified configuration file with his team (for example, through a version control repository or email). This would allow user B to update his default parameter values (according to User A) without having to manually change them in the application (i.e. Edit Between Sessions). All of these mods should happen AFTER CONTROL, Time.]
* I understand that I can “technically” change the user reach settings in the app.exe.config file located in the hidden AppData folder, but this is a hidden file and not all users can have sufficient privileges to view it. (BUT, see “Potential Workaround” above.)