Xamarin.Forms Dropbox integration

Xamarin.Forms Dropbox integration

Xamarin.Forms Dropbox integration (app folder)

Table of Contents

App backup / synchronization between devices

Apps usually backup their content to the respective cloud to ensure local data isn’t lost, but there is of course no guarantee the user has activated those features.

When working with Xamarin/Forms your app is available on more then one device, so you might want to sync files between the OS:s too — like an SQLite database for example.

Complete code for this tutorial: https://gist.github.com/thomashagstrom/b0856a383bcdcf905c7a774c8c1b0879

Dropbox integration (credit: JotForm)

Dropbox v2 API SDK

Dropbox got a new fancy API (v2) and what do you know — there’s an .NET SDK that supports PCL profiles and Mono alike, making Dropbox compatible with Xamarin Droid / iOS / Forms. I’m using Forms in this tutorial, but as long as you roll a PCL / NetCore library for sharing code it should work fine in either case.

I’m going to use the “app folder” type of integration, where your app gets a special folder in the user’s Dropbox, which is a good approach if you’re going to read/write files without user interaction. Alternatively you can check out the full integration, where the user can pick a folder.

Read more:
Dropbox .Net SDK API v2 official documentation

Step 1: Add Dropbox to your Xamarin project

Install the package Dropbox.Api (version 3.5.0 a.t.m) in your XF and platform projects.

Step 2: Authenticate users against Dropbox

The methodology I’m using here is a Webview (integrate a web browser in the app) to display the Dropbox login interface in a modal page and then listening to the navigation event to pick up the Dropbox user token once authentication is complete:


Important configuration here is “YourDropboxAppKey” and “YourDropboxRedirectUri“. To find these, create an app in the Dropbox Developer Console and copy the exact values from your app page.

What I’m doing is fetching an URI to the Dropbox login page for my Dropbox app and displaying this page in a Webview so the user can log in.

Step 3: Get the logged in user’s dropbox token

When the user has logged in to Dropbox the url of the Webview will contain a Token you can use to authenticate all other requests. You should save this token in app settings so you can use it for future requests.


When I’ve saved the token the Webview can be closed by calling PopModalAsync().

List write read files

Good to go! Now that we got a token we can perform common operations as described in the documentation:


Complete code for this tutorial: https://gist.github.com/thomashagstrom/b0856a383bcdcf905c7a774c8c1b0879

Happy coding!

Xamarin.Forms Dropbox integration was originally published in crossplatform on Medium, where people are continuing the conversation by highlighting and responding to this story.

Kontakta app utvecklare

Du kanske även gillar