Search code examples
c#configuration-filesapplication-settings

How is User.config created and how it is used


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 ?


Solution

  • 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.