10

I started reading about config files and I read about user.config. Googled about it, but couldnt find how it is created and how it is used. Also read that for each user a seperate user.config will be created. Even read questions in StackOverflow, but they didnt help. Can anyone point me to the right resources. Thanks in advance :)

Thanks @Ramesh , @Michael and @Frozendragon for your answers. Gone through the articles posted by you. Assume that I have a web application and 3 users named "A", B" and "C" are using them. I have an app.config in which i provided default values. I read that those values can be changed accordinly and will be saved in the UserName.config files. This is where I am lost. If the values are saved in the corresponding user profiles, how are they fetched back when the same user tries to open the app again ? How does my app knows in which files to look ?

Shrikey
  • 858
  • 3
  • 11
  • 34
  • Web Applications cannot have User Scoped application settings. For Web Applications, you will need to handle user settings in some other manner. –  Jul 10 '12 at 07:30
  • Will Hughes ... Oh... Didnt know that. thanks .. :) My actual doubt is.. how is a seperate user.config file created and how it is read. – Shrikey Jul 10 '12 at 07:33
  • @WillHughes In web apps, user based settings can be handled using ASP.NET Profiles – Ramesh Jul 10 '12 at 10:59

3 Answers3

5

Using Settings in C#

User Settings Applied

Michael
  • 8,891
  • 3
  • 29
  • 42
  • If you are having trouble with manually trying to write settings in the app's configuration, then please read the "Using Settings in C#" link above. It will provide the answer to your problems. – Andrew Jens Apr 17 '18 at 22:52
4

To answer the follow-up question of 'How do the User.config files get created':

When you open a Desktop application with User-Scoped settings, the .NET Framework will automatically attempt to load the User.config file for you, from the user's Local Application directory - examine the value of Environment.GetFolderPath(SpecialFolder.ApplicationData) for the exact directory for the current user.

If the file does not exist, then it will be created.

I don't have exact resources to point you at, so the exact time when that file is created may be if it's not found, or it may only be if you call Save on the ApplicationSettings instance.

2

Application Settings Architecture in MSDN, explains about how the settings for an application is loaded and also talk about user-scoped settings which are stored in user.config

Ramesh
  • 13,043
  • 3
  • 52
  • 88
  • I dint get that .. Do u mean user.config exists already and when the app is run, the user-scoped values are stored in user.config ?? Please correct if i understood wrong. – Shrikey Jul 10 '12 at 07:37