title: How to deploy a database file with a Xamarin.from app?
body: <p>I created a sqlite file in my project with some data in it, but I don't know how to link it to my app. I expect the data could be loaded on a Android simulator. </p>
  
  <p>I found a tutorial which was published in 2015, it works no longer, such as GetLocalFilePath function cannot be found after new a FileAccessHelper Class. And the tutorial project seemed using an olde version of SQLite.net-PCL package, because SQLite.Net.Platform.XamarinAndroid was used in the tutorial project, while this package is no longer exist. Any ideas?</p>
  
  <p><a href="http://arteksoftware.com/deploying-a-database-file-with-a-xamarin-forms-app/" rel="nofollow noreferrer">http://arteksoftware.com/deploying-a-database-file-with-a-xamarin-forms-app/</a></p>
  
  <p>This is the code from the tutorial:</p>
  
  <pre><code>[Activity (Label = "People", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
  public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity  
  {
      protected override void OnCreate (Bundle bundle)
      {
          base.OnCreate (bundle);
          global::Xamarin.Forms.Forms.Init (this, bundle);
  
          string dbPath = FileAccessHelper.GetLocalFilePath ("people.db3");
  
          LoadApplication (new People.App (dbPath, new SQLitePlatformAndroid ()));
      }
  }
  </code></pre>
  
  <p>FileAccessHelper.cs</p>
  
  <pre><code>public class FileAccessHelper  
  {
      public static string GetLocalFilePath (string filename)
      {
          string path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
          string dbPath = Path.Combine (path, filename);
  
          CopyDatabaseIfNotExists (dbPath);
  
          return dbPath;
      }
  
      private static void CopyDatabaseIfNotExists (string dbPath)
      {
          if (!File.Exists (dbPath)) {
              using (var br = new BinaryReader (Application.Context.Assets.Open ("people.db3"))) {
                  using (var bw = new BinaryWriter (new FileStream (dbPath, FileMode.Create))) {
                      byte[] buffer = new byte[2048];
                      int length = 0;
                      while ((length = br.Read (buffer, 0, buffer.Length)) &gt; 0) {
                          bw.Write (buffer, 0, length);
                      }
                  }
              }
          }
      }
  }
  </code></pre>