I’m creating an application and I make use of Properties.Settings to store the settings.
However, let’s say my application is on the desktop of the user and is called Program.exe, now, when the user copies this executable and places it somewhere else or even renames it, all settings are gone.
Why is C# doing this? Is there any way this can be turned off while pertaining the user scope? I don’t wish to use the application scope since multiple users can be sharing the same computer.
The settings are likely stored in
{appname}.exe.configwhich apparently is not being copied/renamed with the executable. Either copy the executable with the file, hard-code them in the application, or find another mechanism to get/set app settings (like the registry).The application will look for these settings in a file titled
{appname}.exe.config. If the executable is renamed (without renaming the.configfile) or copied to another location without copying the.configfile along with it, the application won’t know where to look for their settings so they will be blank (unless you set a default value in the app).You can “hard-code” default settings by putting a value in the
Settings.settings“file” in Visual studio (which effectively adds the default value as an attribute to the setting).Another option would be to hard-code the values directly in the source code. I’m NOT recommending this approach as it hinders the ability to change that value, but if you want to be able to deploy the app by just copying the EXE (and nothing else) then it is an option.