How is User.config created and how it is used
Asked Answered
I

3

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 ?

Iranian answered 10/7, 2012 at 6:38 Comment(3)
Web Applications cannot have User Scoped application settings. For Web Applications, you will need to handle user settings in some other manner.Vulgus
Will Hughes ... Oh... Didnt know that. thanks .. :) My actual doubt is.. how is a seperate user.config file created and how it is read.Iranian
@WillHughes In web apps, user based settings can be handled using ASP.NET ProfilesStratopause
V
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.

Vulgus answered 10/7, 2012 at 7:49 Comment(0)
A
5

Using Settings in C#

User Settings Applied

Awning answered 10/7, 2012 at 6:43 Comment(1)
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.Darvon
V
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.

Vulgus answered 10/7, 2012 at 7:49 Comment(0)
S
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

Stratopause answered 10/7, 2012 at 6:41 Comment(1)
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.Iranian

© 2022 - 2024 — McMap. All rights reserved.