Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Accessing the user.config file on a newly installed application from the installer itself

Accessing the user.config file on a newly installed application from the installer itself

Scheduled Pinned Locked Moved C#
helptutorialquestionworkspace
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kaare Tragethon
    wrote on last edited by
    #1

    Dear all. I want to access the user.config file from the installer itself, the problem is that I don't know how to get the path of the newly installed application. I know that the user.config file for my main application is somewhere in "'user'\AppData\Local\.... but I don't know how to access this area from the installer itself. In my main application it is very simple, I just call:

    Configuration _usrConfigLoc = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);

    Inside the installer I have tried:

    Configuration _usrConfigLoc = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);

    This returns the path of the config file of the installer (and not my main application) Does anybody have a way to find the freshly installed user.config file from the installer application?

    H 1 Reply Last reply
    0
    • K Kaare Tragethon

      Dear all. I want to access the user.config file from the installer itself, the problem is that I don't know how to get the path of the newly installed application. I know that the user.config file for my main application is somewhere in "'user'\AppData\Local\.... but I don't know how to access this area from the installer itself. In my main application it is very simple, I just call:

      Configuration _usrConfigLoc = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);

      Inside the installer I have tried:

      Configuration _usrConfigLoc = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);

      This returns the path of the config file of the installer (and not my main application) Does anybody have a way to find the freshly installed user.config file from the installer application?

      H Offline
      H Offline
      hwswin
      wrote on last edited by
      #2
          protected override void OnAfterInstall(System.Collections.IDictionary savedState)
          {
              string t\_path = this.Context.Parameters\["assemblypath"\].ToString();
              Configuration \_usrConfigLoc = System.Configuration.ConfigurationManager.OpenExeConfiguration(Path.Combine(t\_path,"user.config"));
              //...
              base.OnAfterInstall(savedState);
          }
      
      K 1 Reply Last reply
      0
      • H hwswin
            protected override void OnAfterInstall(System.Collections.IDictionary savedState)
            {
                string t\_path = this.Context.Parameters\["assemblypath"\].ToString();
                Configuration \_usrConfigLoc = System.Configuration.ConfigurationManager.OpenExeConfiguration(Path.Combine(t\_path,"user.config"));
                //...
                base.OnAfterInstall(savedState);
            }
        
        K Offline
        K Offline
        Kaare Tragethon
        wrote on last edited by
        #3

        Thanks for the quick reply, however this doesn't work exactly as I want to.... When running this code I get the C:\Program Files\..... folder and the corresponding .config file. However I want to access the .config file which lies in: "Users\user\AppData\Local\CompanyName\AssName++++\VersionNo\user.config" Any ideas?

        H 1 Reply Last reply
        0
        • K Kaare Tragethon

          Thanks for the quick reply, however this doesn't work exactly as I want to.... When running this code I get the C:\Program Files\..... folder and the corresponding .config file. However I want to access the .config file which lies in: "Users\user\AppData\Local\CompanyName\AssName++++\VersionNo\user.config" Any ideas?

          H Offline
          H Offline
          hwswin
          wrote on last edited by
          #4

          Application.UserAppDataPath

          It'll return like follow: "C:\\Documents and Settings\\mis-hongwenshi\\Application Data\\ccc\\WindowsApplication11\\1.0.0.0"

          K 1 Reply Last reply
          0
          • H hwswin

            Application.UserAppDataPath

            It'll return like follow: "C:\\Documents and Settings\\mis-hongwenshi\\Application Data\\ccc\\WindowsApplication11\\1.0.0.0"

            K Offline
            K Offline
            Kaare Tragethon
            wrote on last edited by
            #5

            Thanks again for the very quick replies, however my problem is that I want to find the main application path and not the installer path. If I call Application.UserAppDataPath inside the installer it gives me: C:\Users\Kåre Tragethon\AppData\Roaming\Microsoft Corporation\Windows Installer - Unicode\5.0.7600.16385 I want to be able to find the main application path: C:\Users\Kåre Tragethon\AppData\Local\Tragethon_Teknikk\EasyNetTools.exe_Url_mxn53vo4iinbepot2fslrsybsd0vtoiz\0.8.4.9 Let me know if anything is not clear and I will try to explain some more.....

            H 1 Reply Last reply
            0
            • K Kaare Tragethon

              Thanks again for the very quick replies, however my problem is that I want to find the main application path and not the installer path. If I call Application.UserAppDataPath inside the installer it gives me: C:\Users\Kåre Tragethon\AppData\Roaming\Microsoft Corporation\Windows Installer - Unicode\5.0.7600.16385 I want to be able to find the main application path: C:\Users\Kåre Tragethon\AppData\Local\Tragethon_Teknikk\EasyNetTools.exe_Url_mxn53vo4iinbepot2fslrsybsd0vtoiz\0.8.4.9 Let me know if anything is not clear and I will try to explain some more.....

              H Offline
              H Offline
              hwswin
              wrote on last edited by
              #6

              How about this

              AppDomain.CurrentDomain.BaseDirectory

              I think you deploy the project use the clickonce,am I right?

              K 1 Reply Last reply
              0
              • H hwswin

                How about this

                AppDomain.CurrentDomain.BaseDirectory

                I think you deploy the project use the clickonce,am I right?

                K Offline
                K Offline
                Kaare Tragethon
                wrote on last edited by
                #7

                Thanks again for the very quick replies, and for helping me out and sorry for my bad English and explanations. No I don't use clickonce. I will do some more explaining: I have a main project (main application) which can be installed on any computer. This application contains user settings (user.config) which lies in the following directory: C:\Users\Kåre Tragethon\AppData\Local\Tragethon_Teknikk\EasyNetTools.exe_Url_mxn53vo4iinbepot2fslrsybsd0vtoiz\0.8.4.9 This is the standard location of user settings file, however when the main application changes version a new folder is created, e.g.: C:\Users\Kåre Tragethon\AppData\Local\Tragethon_Teknikk\EasyNetTools.exe_Url_mxn53vo4iinbepot2fslrsybsd0vtoiz\10.8.4.9 I also have an installer application in my project (the standard VS built-in installer). When I un-install the application I want to access the user.config file and get all the settings from this file (and I will save all the settings in the TEMP directory) so that when I install the application again I am able to retrieve all the settings (access the user.config file and write all the previously saved settings). Most often the reason for uninstall->install is that I have made a new version of the software and therefor I cannot rely on a static path to the user.config file, I will have to get it programmaticly.

                H 1 Reply Last reply
                0
                • K Kaare Tragethon

                  Thanks again for the very quick replies, and for helping me out and sorry for my bad English and explanations. No I don't use clickonce. I will do some more explaining: I have a main project (main application) which can be installed on any computer. This application contains user settings (user.config) which lies in the following directory: C:\Users\Kåre Tragethon\AppData\Local\Tragethon_Teknikk\EasyNetTools.exe_Url_mxn53vo4iinbepot2fslrsybsd0vtoiz\0.8.4.9 This is the standard location of user settings file, however when the main application changes version a new folder is created, e.g.: C:\Users\Kåre Tragethon\AppData\Local\Tragethon_Teknikk\EasyNetTools.exe_Url_mxn53vo4iinbepot2fslrsybsd0vtoiz\10.8.4.9 I also have an installer application in my project (the standard VS built-in installer). When I un-install the application I want to access the user.config file and get all the settings from this file (and I will save all the settings in the TEMP directory) so that when I install the application again I am able to retrieve all the settings (access the user.config file and write all the previously saved settings). Most often the reason for uninstall->install is that I have made a new version of the software and therefor I cannot rely on a static path to the user.config file, I will have to get it programmaticly.

                  H Offline
                  H Offline
                  hwswin
                  wrote on last edited by
                  #8

                  :)

                  K 1 Reply Last reply
                  0
                  • H hwswin

                    :)

                    K Offline
                    K Offline
                    Kaare Tragethon
                    wrote on last edited by
                    #9

                    Anyone else?

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups