How to programmatically upload a file to your Dropbox account.
On a train trip during the New Year’s weekend, I spent time testing and collecting notes about how to interact with Dropbox. I will share my findings with you in this blog post.
“Dropbox is a free service that lets you bring your photos, docs, and videos anywhere and share them easily. Never email yourself a file again!” – dropbox.com”
Follow these steps to create a Dropbox account and register the app you will use to interact with your Dropbox file area:
The Dropbox admin interface should now show you the App Key and App Secret you need later for creating a security token file.
My train trip was quite long, so I decided to put another card in the deck. SharpBox is a popular framework for accessing storage and one of the storage service providers it supports is Dropbox. (You can, of course, skip SharpBox and use the Dropbox API directly but I decided out of curiosity to test SharpBox.)
“SharpBox is the right free open source solution for your project. Our goal is to disburden software projects from the demand to implement storage access twice to support a wide range of storage clouds.” – sharpbox.codeplex.com
Follow these steps to set up a test application in Visual Studio 2010 and include Sharpbox in it:
Everything is now set up for some coding. Fill the Program.cs with this:
static void Main()
var dropBoxStorage = new CloudStorage();
var dropBoxConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox);
// declare an access token
// load a valid security token from file
using (var fs = File.Open(@"C:TestDropBoxToken", FileMode.Open, FileAccess.Read, FileShare.None))
accessToken = dropBoxStorage.DeserializeSecurityToken(fs);
// open the connection
var storageToken = dropBoxStorage.Open(dropBoxConfig, accessToken);
var srcFile = Environment.ExpandEnvironmentVariables(@"C:Testtexttest.txt");
// close the connection
After executing the application, you should be able to see in your Dropbox client of choice or Dropbox admin interface that the file texttest.txt has been uploaded to your Dropbox file area.
I have now successfully stored files this way for more than a month in a minor hobby application and it works great. After uploading files, you probably also want to download them and SharpBox can help you with this and much more. The only problem I encountered in my own application was when trying to download a file from Dropbox and sending it to the user via a Web browser as a stream. The file had the correct size, but seemed to be empty. The solution was to use Stream.Seek(0,0) before returning the filestream.
You can find more info here:
A lot of response lately reported problems about creating the token file. I have tried to get in contact with the dev team behind SharpBox without success and your questions at the SharpBox forum are leaved without answers. The project might unfortunately be dead, but my suggestion is to continue to use their forum and try to get in contact with the dev team to solve the problem. You are welcome to write a comment here if you have an update about the SharpBox Project status