none
Where to store/search for configuration files RRS feed

  • Question

  • Hi,

    I developed a C# Windows Forms application that, during its setup, launches a custom action that creates a database in the specified database server. Once it finishes, it creates an xml file where it stores, among other things, which server to connect to, which type of authentication is used, login name if aplies, etc.

    Since I want o be able to deploy my application in Windows Vista, in the custom action, I save the file in

    Application

     

    .LocalUserAppDataPath + "\\appname.xml"

    This works OK as far as the program is installed on a per user basis, but if you use an administrator user to install it as shared, when you log on as a regular user, its LocalUserAppDataPath won't contain the <appname.xml> file, and, thud, it won't be able to connect to the DB, etc.

    Is there a way to know which type of installation was chosen? This way, my custom action and the application itself would be able to tell if it has to access Application.LocalUserAppDataPath, Application.CommonAppDataPath, Application.UserAppDataPath, or whatever folder it may contain the configuration files? Is my approach correct?

    Thanks in advance,

    Dani Carbonell
    Tuesday, June 16, 2009 6:20 AM

Answers

  • Use two of them then.  Note that the ConfigurationSetting class is designed to handle the "save user settings" scenario, Project + Properties, Settings tab.

    Hans Passant.
    Tuesday, June 16, 2009 9:29 AM
    Moderator

All replies

  • Why you are not placing the file inside the application installation folder?



    Thanks,
    A.m.a.L
    .Net Goodies
    Remember to click "mark as answered" when you get a correct reply to your question
    Tuesday, June 16, 2009 6:35 AM
  • That is what I used to do, but if I do, Vista will require administrator rights to run the application, and is not suitable in some contexts.
    Tuesday, June 16, 2009 7:00 AM
  • You have one shot at admin privileges, at install time.  The .xml file you describe needs to be writable during that time.  After that it just provides info that only needs to be read.  Storing it in the .exe folder is certainly the logical place.

    Hans Passant.
    Tuesday, June 16, 2009 7:45 AM
    Moderator
  • Thanks, Hans, that would work, but in this case, non-admin users do need write access to a "provate" xml file because it stores, additionally, some other options the user chooses.
    Tuesday, June 16, 2009 8:25 AM
  • Use two of them then.  Note that the ConfigurationSetting class is designed to handle the "save user settings" scenario, Project + Properties, Settings tab.

    Hans Passant.
    Tuesday, June 16, 2009 9:29 AM
    Moderator
  • Two files? It sounds good, one of them could be stored in CommonAppDataPath folder (or in the application installation folder, as suggested before), which would be shared among all users and written only at install time by an administrator, and the other, at LocalUserAppDataPath for every user to modify it.

    If, some other time, he configuration has to be changed, an administrator can take care.

    For that purpose though, I need to assume the installation is done by an administrator and that the opction "install for all users" is selected, is there a way to force the application to be installed "for all users"?

    Tuesday, June 16, 2009 10:23 AM