how to change .NET user settings location
Asked Answered
C

3

12

By default settings are stored at: C:\Documents and Settings\\Local Settings\Application Data\<Project Name>

How can I change this path to application directory. I also don't want to have different files for different users. How make the settings global?

I tried to change the scope of the settings to "application" but then I cannot change them at runtime.

Copyedit answered 25/3, 2010 at 19:36 Comment(0)
M
14

Using the default built-in behavior you can't!

Q: Why is the path so obscure? Is there any way to change/customize it?

A: The path construction algorithm has to meet certain rigorous requirements in terms of security, isolation and robustness. While we tried to make the path as easily discoverable as possible by making use of friendly, application supplied strings, it is not possible to keep the path totally simple without running into issues like collisions with other apps, spoofing etc.

The LocalFileSettingsProvider does not provide a way to change the files in which settings are stored. Note that the provider itself doesn't determine the config file locations in the first place - it is the configuration system. If you need to store the settings in a different location for some reason, the recommended way is to write your own SettingsProvider. This is fairly simple to implement and you can find samples in the .NET 2.0 SDK that show how to do this. Keep in mind however that you may run into the same isolation issues mentioned above .

I agree with Robert Harvey's answer do it yourself, or write a custom settings provider.

Manikin answered 25/3, 2010 at 21:7 Comment(1)
The link you provided is for an old Visual Studio manual. I can't find anything about a custom setting provider. Can you give further information regarding this topic?Trevino
A
0

You can always read and write your own XML configuration files.

Anhanhalt answered 25/3, 2010 at 19:44 Comment(0)
L
0

There are difficulties with programmatically changing settings for all users (since they come from the exe.config file, which is usually in Program Files and thus protected from write access in modern OSes). You can try making the settings application-wide but then use the ConfigurationManager to mess with the config file, similarly to the solution to this question.

Lenlena answered 25/3, 2010 at 20:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.