Deploying a SQLite database file with a Xamarin.Forms app–(UWP update)

Say you have a SQLite DB you want to deploy with your Xamarin Forms app. Here is an excellent article on how to do this from Rob Gibbens of Xamarin University fameā€¦

http://arteksoftware.com/deploying-a-database-file-with-a-xamarin-forms-app/

The article has wp8 but it uses Application.GetResourceStream and that is only for Windows phone, and the code below I have updated for UWP. Also, in November the UWP team posted some great sample code where I found the answer at: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/FileAccess

So, just replace the WP8 code in the blog article with this code below and you will all set. The iOS and Android code works fine in the blog.

var storageFile = IsolatedStorageFile.GetUserStoreForApplication();

if (!storageFile.FileExists(dbPath))

{
// copy storage file; replace if exists.
var fileToRead = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri(“ms-appx:///people.db3″, UriKind.Absolute));

Windows.Storage.StorageFolder storageFolder =

Windows.Storage.ApplicationData.Current.LocalFolder;

StorageFile fileCopy = await fileToRead.CopyAsync(storageFolder, “people.db3″, NameCollisionOption.ReplaceExisting);

}