title: Xamarin: how to backup/sync a sqlite database with DropBox or Google Drive
body: <p>I have an app written using Xamarin for Android that allows me to store my customers info. I store all the data locally using sqlite and it all works fine. But I need to share this info with my colleague who is using the same app on his phone. So for example, if I add a new customer order from my phone this will be saved into my local db.
  Now I want to hit a button to trigger the sync of my local db with some backup of this db stores in a shared folder in Dropbox or Google Drive.,</p>
  
  <p>From suggestions below, I am trying to use DropBox Core Api. I got to the point where I authenticate to access my account, now I need to copy my local DB in my app folder in Dropbox. I am using the code below for my second activity. When it launches, I get the authentication page for Dropbox. After that when I click the backup button I am expecting to read the local DB and save it to Dropbox under ./Apps/ClientsApp/. But I only get a generic error (An unhandled exception occured). Where am I making a mistake?</p>
  
  <pre><code>using Dropbox.CoreApi;
  using Dropbox.CoreApi.Android;
  using Dropbox.CoreApi.Android.Session;
  
  namespace my_app
  {
  [Activity(Label = "Second Activity")]
  class clientsDB : Activity
  {
      string AppKey = "myAppKey";
      string AppSecret = "myAppSecret";
      DropboxApi dropboxApi;
      private Button backup;
  
      protected override void OnCreate(Bundle savedInstanceState)
      {
          base.OnCreate(savedInstanceState);
          SetContentView(Resource.Layout.clientsDB);
  
          // dropbox
          AppKeyPair appKeys = new AppKeyPair(AppKey, AppSecret);
          AndroidAuthSession session = new AndroidAuthSession(appKeys);
          dropboxApi = new DropboxApi(session);
  
          (dropboxApi.Session as AndroidAuthSession).StartOAuth2Authentication(this);
  
          backup = FindViewById&lt;Button&gt;(Resource.Id.backup);
          backup.Click += Backup_Click;
      }
  
  
      private void Backup_Click(object sender, EventArgs e)
      {
          string origin = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "dbClients.db3");
  
          string dropboxPath = @"./Apps/ClientsApp";
          upload(origin, dropboxPath);
  
      }
  
      // use async cause I had Android.OS.NetworkOnMainThreadException 
      async void upload(string origin, string destination)
      {            
          using (var input = File.OpenRead(origin))
          {
              // Gets the local file and upload it to Dropbox
              dropboxApi.PutFile(destination, input, input.Length, null, null);
          }
      }
  
      protected async override void OnResume()
      {
          base.OnResume();
  
          // After you allowed to link the app with Dropbox,
          // you need to finish the Authentication process
          var session = dropboxApi.Session as AndroidAuthSession;
          if (!session.AuthenticationSuccessful())
              return;
  
          try
          {
              // Call this method to finish the authentication process
              session.FinishAuthentication();
          }
          catch (IllegalStateException ex)
          {
              Toast.MakeText(this, ex.LocalizedMessage, ToastLength.Short).Show();
          }
      }
  
  
  }
  }
  </code></pre>