Search code examples
winformswindows-installersetup-deployment

Asking user to use or not the old installation setting during new installation


My application keeps user's input for application setting in a XML file. Now suppose I have uninstalled my application but the setting file(xml file) is still there. It has not been removed. I want to use that setting file for my next installation. Is there any way to ask user during installation like "Do you want to use existing setting?". So that I do not need to initialize the setting again after new installation.


Solution

  • Yes you can do it, First of of all you have to make sure that already created XML file is not being removed when application is uninstalled. By default when you uninstall an application files deployed with the MSI will get removed when its uninstalled. To prevent this go to that specific file property and set Permanent to True.

    You have to add installer class to your set up project. within install method check if the XML file exisit. If then display confirmation message to user. based on the user preference either keep old xml file or add a new file to save the new settings again.

    public override void Install(System.Collections.IDictionary stateSaver)
    {
        //Invoke the base class method
        base.Install(stateSaver);
    
        if (File.Exists("XML File path"))
           {
               DialogResult result = MessageBox.Show("Do you want to use existing setting?","",MessageBoxButtons.YesNo);
    
            if (result.Equals(DialogResult.Yes))
               {
    
               }
            else
               {
    
               }
           }
    }