none
user.config location RRS feed

  • Question

  • hi, my app stores some settings data in the user.config file. this one is located in
    InstallRoot%\Documents and Settings\username\Local Settings or appdata.

    How can i modify this location of the user.config file (for example i want it always to be in the same dir of my app or a subdir of it.

    Havent been able to figure it out , anyone knows ?

    thanks,
    Bruno
    Friday, June 17, 2005 11:40 PM

Answers

  • You have to write your own settings provider to do this. http://msdn2.microsoft.com/library/f6wys023(en-us,vs.80).aspx

    Please note that it is *not* recommended to store user settings in the application directory.

    "Normal" users should not have write access to this directory, so you will run into problems when someone tries to run your application as a non-administrator.

    Best regards,
    Johan Stenberg
    Tuesday, June 21, 2005 12:14 AM
    Moderator

All replies

  • You have to write your own settings provider to do this. http://msdn2.microsoft.com/library/f6wys023(en-us,vs.80).aspx

    Please note that it is *not* recommended to store user settings in the application directory.

    "Normal" users should not have write access to this directory, so you will run into problems when someone tries to run your application as a non-administrator.

    Best regards,
    Johan Stenberg
    Tuesday, June 21, 2005 12:14 AM
    Moderator
  • Dear Johan,

    Thank you for your answer. I do agree with you on this partially. Normal users in a corporate environment Yes but waht about all the Home users to which some of my software is targeted ??? I have a problem :

    None of these users will ever find that user.config file back (its so well hidden in the C:\documents and settings\....), what if i want a user to be able to move his settings and all config options I stored in this file to a new computer for example ? Or to just make a simple backup ? Write tools to do this , is that the recommended action ?

    thanks,
    Bruno
    Thursday, June 23, 2005 6:49 PM
  • You should check out 'Best Practice Guidelines for Creating Applications that Migrate Easily':

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsetup/html/migrationbkm09.asp

    This may help clear things up for you. I would assume you would need to write your own migration tools.

    -Joe
    Thursday, June 23, 2005 10:09 PM
  • Is it possible to write a class that inherits from LocalFileSettingsProvider and override the method (if there is one) that determines the location of the user.config file?
    Tuesday, July 11, 2006 6:37 PM
  • The LocalFileSettingsProvider actually uses the configuration system to figure out where the file is to be located (the exact location depends on factors such as if the application is click-once deployed or not) so no, this is not easily done.

    Best regards,
    Johan Stenberg

    Tuesday, July 11, 2006 8:26 PM
    Moderator
  • Darn.  Writing my own SettingsProvider looks more complicated than what I would like.

    The end result that I want is that most things would behave the same as if I was using LocalFileSettingsProvider except that the location of the user.config file is different.

    But how do I ensure this?  Basically, I have no idea what LocalFileSettingsProvider is doing.  Java provides the source code for it's libraries -- does .Net do the same?  Can I look at the source code for LocalFileSettingsProvider to see what it is doing?

    I personally would rather just let .Net handle the location and management of the config files but my workplace has this standard of placing user config files on a certain networked drive.  But I really want to use .Net's application/user settings framework -- it's really nice and saves me a lot of work!  If only I could easily change the location of the user.config file.

    My hope was to quickly be able to use .Net's application/user settings framework (with the modification that it uses the networked drive to store user.config) to do my current project and then later try to convince my  project leaders that it might make more sense to just go along with the default .Net behavior for the location of the user.config files.
    Wednesday, July 12, 2006 12:55 AM