David Ly
David Ly

Reputation: 31586

Is there a way to tell .NET where to look for the user settings file?

Basically multiple instances of our application will be launched but they need to have separate user settings. We currently have use "user settings" for that, and it works fine for a single instance (per windows user) but we would like to be able to launch multiple instances with say a settings path passed in via command line. Is there a way to do this with the built-in .NET settings or will we have to roll our own?

Upvotes: 3

Views: 321

Answers (5)

Daniel Rose
Daniel Rose

Reputation: 17638

There is an interesting CodeProject article which has a custom settings provider. You only need a small tweak of your code, and then it allows you to save and load your settings to a file location you provide.

Upvotes: 0

user171523
user171523

Reputation: 4345

I would suggest to store the config information in DB and read based on the user. Any case you have to maintain the user specific information different copies. Onload of the application read from DB and cache all the settings.

User User Personalization and profile API to retrieve the information. It is very easy to update the information in DB rather then dealing with files which are located in users systems.

Upvotes: 0

Hans Passant
Hans Passant

Reputation: 941357

The LocalFileSettingsProvider class, the one that manages the file with user settings, is quite impossible to tweak. Whomever wrote that must have been paralyzed by security concerns. Perhaps not unjustified.

If you want to stick with System.Configuration then you'll need to implement your own provider. Probably the best way to do that is to start from the RegistrySettingsProvider sample. It won't help you get the file handling right but at least you'll have something to build on. A couple of peeks with Reflector can help.

Upvotes: 3

Payton Byrd
Payton Byrd

Reputation: 986

.Net has a Configuration Provider API. app.config is just a predefined implementation of that API. You should look into using the API to either extend the built-in API, or create your own.

Upvotes: 0

Michael Rodrigues
Michael Rodrigues

Reputation: 5137

I recommend developing a class that will handle app settings and accepts a filename. I've had to do this for DLLs that needed app settings, and it also helps if you want to store your settings in a non-local location (e.g. single place on the network).

It will give you a lot more flexibility - It's definitely worth the investment!

Upvotes: 2

Related Questions