Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I bundle my database file into my app, ready for a side load install?

I am creating a Windows 10 Universal App which uses a local SQLite Database. In order for the app to use the database file It must be placed in:

C:\Users\<Username>\AppData\Local\Packages\<Name of Package>\Local State

Now I understand this is the 'local' file structure for the application. However I have a pre-made database that the app needs to interact with and therefore should be bundled as part of the app on install.

Is there a method of including my database in a usable fashion when distributing my application via a side-load install?

Furthermore, This problem is of paramount importance as This 'C:\' Directory will not exist when pushing my application to the mobile phone or other Windows 10 (not a desktop) device.

like image 297
Harvey Avatar asked Oct 07 '15 15:10

Harvey


1 Answers

You cannot package the database directly as read-write data (local state). If you only ever need to read from the database, you can just include it in your project and read it from Package.Current.InstalledLocation.

If you need to write to the database, but it contains some initial values you want to ship with your app, then you still need to include the database in your project, but then copy it from the InstalledLocation to ApplicationData.Current.LocalFolder if it doesn't exist when your app starts up.

like image 70
Peter Torr - MSFT Avatar answered Sep 18 '22 14:09

Peter Torr - MSFT