Copying SQLite DB from Bundle to Library

I am contemplating switching my companies app from Adobe AIR to Xamarin and I am working on making a prototype to show management what Xamarin can do. One thing that will be required is allowing the app to work completely offline. We currently achieve this by packaging a SQLite DB with the app, this DB is then copied to the user's Application Storage Directory, or Library, and then that is the DB that is used by the app and updated when they have a network connection. I know this is pretty common practice, so I was looking if anyone on here has any advice on doing this type of operation with Xamarin.iOS and Xamarin.Android. I have come across many resources on using a SQLite DB with the apps, but I cannot find much on copying files from the Bundle to the Library for use. Any help is greatly appreciated.

Answers

  • TedRogersTedRogers USMember ✭✭✭✭

    Just a file copy. You just need to get the right paths.

    Resource path is retrieved dong something like this on iOS. There is no cross-platform way that I know of to get to path of files in bundle.

    var pathToResoure = NSBundle.MainBundle.PathForResource(resourceName, type);

    Destination you can get either using native methods or something like this:

    var destPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

    You can then copy the file doing this:

    System.IO.File.Copy(fromPath, toPath, overwrite);

Sign In or Register to comment.