user1860934
user1860934

Reputation: 427

How to prevent settings.settings file reset after each new installation

So I have WPF application and I am using settings.settings file to save several settings for example specific Path that the user need to set and I am also create a exe installation file using Advanced installer and after install new application version all the application files (include the application exe file) replaced with the new version and in such case all settings.settings variables reset and I want to prevent it.

Any ideas ?

Upvotes: 0

Views: 565

Answers (2)

Skyfish
Skyfish

Reputation: 137

For Windows Forms apps I use code like this in my main form, after the call to InitializeComponent(). It copies the settings from the previous version the first time the new version runs.

if (Properties.Settings.Default.FirstTimeRunningThisVersion)
{
   Properties.Settings.Default.Upgrade();
   Properties.Settings.Default.FirstTimeRunningThisVersion=false;
   Properties.Settings.Default.Save();
}

FirstTimeRunningThisVersion is type bool and its default value must (obviously) be True.

Upvotes: 0

Midn1ght
Midn1ght

Reputation: 11

If I understand correct, when you upgrade your application you want your settings.settings file to be saved. If you don't want to use "Side by side install", you can do this:

  1. On install time, from AI, add a "New File Operation" and copy your file to an backup folder for example.
  2. Now you need to copy back your file when the new application is installed. You need to add a script with custom action with sequence (Launch file for .bat, or PowerShell inline script). You can do that with .bat or PowerShell. I recommend you .bat since is more easy. Configure this custom action to be be executed "When the system is being modified (deferred)", check "Run under the LocalSystem account" and also on "Execution Stage Condition" select only "Install". You can find how to copy files in .bat on google, it's something with xcopy /Y %1 %2

If this is what you need and you can't implement it, just tell me and I will try to help you.

Upvotes: 0

Related Questions