locked
app.Config file entries are cleared on Repair RRS feed

  • Question

  • Hi,

    I have created a Setup Project for my Project. This project connects to a live DB server through asmx services. That URL will be determined after the client will deploy the web services on some server. So in setup project i have added a "TextBoxes" dialog in User Interface Editor section of the Setup Project where i have enabled only one TextBox to get the URL of the deployed Services. In my project i have added a file to be executed during Setup installation and i have defined it as follows:

     

    [RunInstaller(true)]
    public class InstallerHelper : System.Configuration.Install.Installer
    {
        // Other Code also exists that is not needed to be shown here<br/>    //.....<br/>
        // The following method gets executed during setup installation
        public override void Install(IDictionary stateSaver)
            {
                try
                {
                    base.Install(stateSaver);
                    //Proceed only if the Context object has some parameters
                    if (Context.Parameters.Count != 0 && !string.IsNullOrEmpty(Context.Parameters["WEBSITEURL"]))
                    {
                        //Get the installation Folder's Path
                        string installationFolder = Context.Parameters["INSTALLFOLDER"];
                       // Get the Site's URL entered by Client
                        string websiteUrl = Context.Parameters["WEBSITEURL"];
                       //Create different Key Value pairs based on entered URL
                        string[][] keyValues = {
                                        new string[] {"SiteUrl",websiteUrl},
                                        new string[] {"WebServiceURL", websiteUrl + "Users.asmx" },
                                        new string[] {"TicketsServiceURL", websiteUrl + "Tickets.asmx"},
                                        new string[] {"CampaignsAndProjetcsServiceURL", websiteUrl + "CampaignsAndProjetcs.asmx"},
                                        new string[] {"EntitiesURL", websiteUrl + "Entities.asmx"},
                                        new string[] {"AccountsURL", websiteUrl + "Accounts.asmx"},
                                        new string[] {"TransactionsURL", websiteUrl + "Transactions.asmx"},
                                        new string[] {"RelatedReportsURL", websiteUrl + "RelatedReports.asmx"},
                                        new string[] {"GiftAidsURL", websiteUrl + "GiftAids.asmx"}
                                       };
    
                      // Load the app.Config file and store these values in it.
                        //********************************************
                        string configFilePath = installationFolder + @"\MyProject.exe.config";
                        XmlDocument configuration = new XmlDocument();
    
                       // Load App.Config File
                        configuration.Load(configFilePath);
    
                        //Add the values in it
                        Utility.UpdateValue(keyValues, configuration);
    
                     //Save configuration File
                        configuration.Save(configFilePath);
                      //********************************************<br/>
                    }
                }
                catch (Exception ex)
                {
                    throw new InstallException("The following Error(s) occured during installation. \n " + ex.Message);
                }
            }
    
    }
    


    Here i Store the entered URL and some other generated URLs of different web services in App.Config of the Project to be used in Project for accessing data.

    It works fine when i install a fresh copy of the Setup, but problem occurs when i try to Repair the installed project by again executing the Setup.exe file.

    Repair process does not asks me to enter the URL again and also the Items stored in App.Config during first time installation are lost. So the whole application stops working.

    Any help is greatly appreciated.

     




    • Edited by khawarhabib Monday, October 24, 2011 9:15 AM
    Monday, October 24, 2011 8:13 AM

Answers

  • A good approach is to save this custom information somewhere and retrieve it during maintenance using searches:

    • create some string registry entries which contain your custom properties; the registry entry value can be something like:

    [WEBSITEURL]

    • create registry searches which read these entries and save them in your custom properties; for this use the property names for the actual searches

    This way a repair will read the property values from registry and restore your original properties.


    Cosmin Pirvu
    My blog | Contact me
    Please remember to mark the replies as answers if they help.
    • Proposed as answer by Neddy Ren Wednesday, October 26, 2011 8:46 AM
    • Marked as answer by Neddy Ren Wednesday, November 2, 2011 2:27 AM
    Monday, October 24, 2011 11:04 AM