1

My C# program has an app.exe.config file. User can install the program anywhere. If the user chooses to install the program in the "Program Files" folder, the program will have privilege problems modifying files in Windows 7, so I've externalized the files that can be modified to the AppData folder. Except app.exe.config file, that should also be modifiable by the program when user changes its settings. Apparently it should be in the same folder as where app.exe.

I think this is a quite trivial problem, however I cannot find the right solution.

  • Copying the config file elsewhere, modifying it and copying back to Program Files;
  • Creating a second config file elsewhere;
  • Not giving the user the choice of installation folder;
  • Forcing the program to be run as admin.

All of these solutions would lead to a bad design. What solution wouldn't?

EDIT: Maybe some of my premises are wrong and it is possible to have the config file installed to AppData or anywhere else without changing the executable's location. I haven't yet found for sure if this is possible, however.

Limbo Exile
  • 1,321
  • 2
  • 21
  • 41
  • possible duplicate of [Relocating app.config file to a custom path](http://stackoverflow.com/questions/1838619/relocating-app-config-file-to-a-custom-path) – tschmit007 Jul 09 '14 at 13:34
  • Load the app.config at runtime. http://stackoverflow.com/a/6151688/1537422 – Ramesh Durai Jul 09 '14 at 13:42

2 Answers2

2

The Application Settings Architecture should help you - you can define user settings as well as application settings that are stored in a user.config file.

Reference to MSDN: http://msdn.microsoft.com/en-us/library/0zszyc6e(v=vs.110).aspx

"Non-default user-scoped settings are stored in a new file, user.config, where user is the user name of the person currently executing the application. You can specify a default for a user-scoped setting with DefaultSettingValueAttribute. Because user-scoped settings often change during application execution, user.config is always read/write."

1

Change app.config file permissions upon installation. If you are using WIX (I'm just assuming since it's the most popular solution nowadays) have a look at http://wixtoolset.org/documentation/manual/v3/xsd/util/permissionex.html

wade
  • 153
  • 9