Some days ago, I was faced with the task of developing Dropbox connector that should be able to enumerate and download files from Dropbox. The ideal case for me is a wrapper library for .NET 3.5 with an ability to authorize in Dropbox without user interaction. This is a list of .NET libraries/components that are currently available:
- DropNet (NuGet package)
- SharpBox (NuGet package)
- Spring.NET Social Dropbox
- Xamarin Dropbox Sync component.
Sprint.NET and Xamarin component are not my options for now. DropNet also does not fit my needs, because it is .NET 4+ only. But if your application is for .NET 4+, then DropNet should be the best choice for you. I chose SharpBox, it looks like a dead project – no commits since 2011, but nevertheless the latest version is available on NuGet.
At the beginning, you need to go to Dropbox App Console and create a new app. Click on “Create app” button and answer to the questions like in the picture below.
When you finish all these steps, you will get an App key and App secret, please copy them somewhere – you will need them in future. Now we are ready to create our application. Let’s create a new F# project and add AppLimit.CloudComputing.SharpBox package from NuGet.
After package is downloaded, go to packages\AppLimit.CloudComputing.SharpBox.188.8.131.522\lib\net40-full folder, find and start DropBoxTokenIssuer.exe application.
Fill Application Key and Application Secret with values that you received during app creation, fill Output-File path with c:\token.txt and click “Authorize”. Wait some seconds(depends on your Internet connection) and follow the steps that will appear in browser control on the form – you will need to authorize in Dropbox with your Dropbox account and grant access to your files for your app. When file with your token will be created, you can click on “Test Token” button to make sure that it is correct.
Using token file, you are able to work with Dropbox files without direct user interaction, as shown in the sample below:
open System.IO open AppLimit.CloudComputing.SharpBox [<EntryPoint>] let main argv = let dropBoxStorage = new CloudStorage() let dropBoxConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox) // load a valid security token from file use fs = File.Open(@"C:\token.txt", FileMode.Open, FileAccess.Read, FileShare.None) let accessToken = dropBoxStorage.DeserializeSecurityToken(fs) // open the connection let storageToken = dropBoxStorage.Open(dropBoxConfig, accessToken); for folder in dropBoxStorage.GetRoot() do printfn "%s" (folder.Name) dropBoxStorage.Close() 0