Jalle
Jalle

Reputation: 97

Windows Store Application and SQLite user data

I have Metro app with SQlite DB that is pre populated with some data. User is allowed to change and add more data.

The question is: How do I preserver user data between app updates ? And which folder should I choose :

Windows.ApplicationModel.Package.Current.installedLocation or Windows.Storage.ApplicationData.Current.LocalFolder ?

Upvotes: 0

Views: 48

Answers (1)

Rob Caplan - MSFT
Rob Caplan - MSFT

Reputation: 21899

You'll probably want to use both locations.

InstalledLocation includes any data that ships with the app. It is read-only, and so the user cannot change or add data in that location.

The ApplicationData folders are per-user and writable. They will persist through updates.

The typical pattern is to ship your pre-populated database in your app package so it is installed in the installedLocation folder. When the app first runs it can copy the database from the installedLocation to the ApplicationData folders, and the app can then use the data from there.

So long as the app doesn't copy over any data already in the ApplicationData folder then the user's data will persist between updates. If the user just adds data and doesn't change the pre-populated data, or if the pre-populated data doesn't change with updates then this is easy. You can just copy any new data over but not overwrite existing data.

If the user can change the pre-populated data and if the update can change the prepopulated data then this gets a bit trickier: you will need a system to know if the current data came from the user or not, and then update it only if it didn't come from the user. How best to do this will depend on the database and the data. Two possibilities would be a modified column or a time stamp.

Upvotes: 1

Related Questions