The .NET configuration settings feature is not as flexible as I would like. If I understand Application Settings correctly, I am limited as to when I can change/edit settings. In C#, Application Settings are divided into two different types or scopes ("Application" and "User"), but both have limitations in regard to how they can be changed or modified. The following table demonstrates the differnce:
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
Is there any "built-in" settings functionality that will allow me to edit settings by all three mechanisms? One of the primary motivations for using a configuration file is to allow users to change default values without re-building the source code (as can be done with Application-scoped settings). However, the user shouldn't be forced to edit a .config file; they should also be able to make a change at run-time that persists across settings (as can be done with User-scoped settings). Surely there must be some sort of mechanism that provides both functionalities.
BOTTOM LINE: Why can't Application Settings (app.exe.config
) be edited at Run-Time? That would solve all my problems. I understand that this could cause problems for users who share the same machine. But who does that anymore?
POTENTIAL WORKAROUND: Is there anyway to change the default storage location for the User Settings config file into a non-hidden folder?
UPDATE (for clarification):
What I'm saying is that I want to be able to change a default setting at Design-time, at Run-time, or in-between sessions (i.e., by editing a config file). But when using the built-in C# persistence mechanisms provided by Settings.settings
, I must choose at most 2 out of the 3. Am I missing something? Is there another alternative that I am not aware of?
[Use Case: I want to store a "default" database name for the connection string, but I want the user to be able to specify a different database at runtime (and thereby become the "new" default for that user). But I also want to be able to over-write the default in the config file without re-running or re-building the application.]
[BETTER Use Case: (In response to comments)
I have a computational model with a config file that contains the default values for parameters in the model. User A starts up the model and decides to change the value of several of the parameters. That change needs to persist for all future sessions for that user (i.e., Edit at RunTime). Subsequently, that user wants to share that modified configuration file with his team (via version control repository, for example, or email). This would allow User B to update her default parameter values (to match User A's) without having to manually change them in the application (i.e., Edit Between Sessions). All of these mods should happen AFTER Design-Time.]
*I realize that I can "technically" edit user-scoped settings in the app.exe.config file located in the hidden AppData folder, but this is a hidden file and not all users may have sufficient privileges to view it. (BUT see "Potential Workaround" above.)