Skip to main content

On Properties.Settings.Default.Upgrade();

At some point in the last few years, the ability to upgrade one's Windows app's config file broke. Previously, this code would perform the upgrade:

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

For some reason, though, this no longer works, and hasn't for some time. Which means you really have to roll your own implementation.

What I did was create two methods for XML file handling. One saves the current options to disk, and another loads them. I plug the one that saves into the app's form's closing method, and I insert the other into the code I just showed you.

if (Properties.Settings.Default.UpgradeRequired)
  {
      UpdateOptions();
      Properties.Settings.Default.UpgradeRequired = false;
      Properties.Settings.Default.Save();
  }
When I call UpdateOptions(), it loads the latest options from disk and then sets the app's properties to those options before saving again using Properties.Settings.Default.Save().

The net result is every time the app closes, a copy of the app's options are saved to disk. And every time a new version of the app start's up, since Properties.Settings.Default.UpgradeRequired will be true (when you add this Boolean setting to project, you set it's default value to True), you'll update the options to those stored in the XML file and then re-save them, thus preserving the previous versions options.

And when I say options, I means settings. Microsoft called them settings, and they are typically stored in the config file, but in my case they are program options.

Comments

Popular posts from this blog

MaxLeafSoft Privacy Policy

MaxLeafSoft and its applications never store your personal data.


Comparison of Sync2Folders Pro to BASK

It wouldn't make sense to compare Sync2Folders Pro to Beyond Compare or other mature, well established programs with similar functionality. This is true for a number of reasons, including:
Sync2Folders Pro doesn't offer a way to compare file contents or to copy contents line-by-line from one file to another.Sync2Folders Pro isn't backed by a team that has programmers as skilled as those at Scooter Software and elsewhere. I am capable, but this isn't my main job, and as such, I'm not as good as they are!Sync2Folders Pro is free. There are other free utilities that are probably more robust, but that's not the point. The point is, I'm not going to compare this program to the competition because there is no competition here. I wrote Sync2Folders Pro for myself, and the only utilities I'll compare it to are those I also wrote. I could compare it to Sync2Folders Lite, but it surpasses that program handily. Sync2Folders Pro has an entirely new code base, and ha…