Maryam
Maryam

Reputation: 913

ApplicationData version in UWP

I Have a blank UWP Application, I wrote some setting in ApplicationData , when I increase My package version, My applicationData version doesn't change. another problem is when I set my AppData version with SetVersionAsync method and after that I read setting from myAppData, it reads latest setting that has been wirtten while I am expecting not to read the latest because the version is different. can somebody tell me why?

Upvotes: 2

Views: 449

Answers (1)

Damir Arh
Damir Arh

Reputation: 17855

I don't think you're approaching the application data versioning correctly. There is no direct correlation between the package version and the application data version. The point of application data versioning is to allow changes to the format you're using for application data between application versions.

This is the typical scenario:

  1. In the first version of your application you just save the data to application data, paying no attention to the version. Implicitly the version will be set to 0. You keep doing this until you need to change the format of the data you are saving.
  2. When you finally need to change the format of stored data, you will start paying attention to the version of application data. You will first check the value of ApplicationData.Version. If its value is 0, you will use the old code for loading the data. Once you're done, you will call ApplicationData.SetVersionAsync, set the version to 1 and save the loaded data in the handler according to the new format. The next time your application loads, the application data version will be 1 and you will use the new code to load it.
  3. You will repeat the process every time, you will want to change the format, incrementing the application data version (usually by 1). You will always need to support loading of all old versions of application data, because the user could have last saved the data using any previous version of the application, before finally trying to load it with the latest version. After loading the data, you will always save it in the latest format, by calling ApplicationData.SetVersionAsync with the latest value for the application data version.

Upvotes: 7

Related Questions