24 March, 2011

DropBox: how to upload files to DropBox using code

DropBox is a great little service that simply “just works”. If you have a DropBox account and wish to operate this from code, you have to know a great deal about REST and other “webby” stuff to communicate with the DropBox account. But, a great little library exists that shields you from all of this. On “github” (what ever that means?) ) you will find the DropNet library that helps you out here. It will allow you to operate the DropBox account quite easily.

How to do ?
1) Register a developer account at Dropbox.com
2) Obtain the ‘key’ and ‘secret’ from DropBox.com (found under ‘My Apps’)
3) Call into the users DropBox account like below

static void Main(string[] args)
var client = new DropNet.DropNetClient("32131rwzxynxo50t", "fwwesodkiwud8");

client.Login("user@domain.com", "password");

Console.WriteLine("Uploading file...");

//update file (testfile1.txt) -> dropbox
byte[] rawData = File.ReadAllBytes("textfile1.txt");
var result = client.UploadFile("Test", "textfile1.txt", rawData);

Console.WriteLine("Status = {0}", result.StatusCode);

As evident from the sample, you can stream the file to DropBox using the client.UploadFile(<folder>, <filename>, <raw bytes>).

Technorati Tags: ,


Anonymous said...

Hello Sir,

Could you explain these lines of code:

var client = new DropNet.DropNetClient("32131rwzxynxo50t", "fwwesodkiwud8");

client.Login("user@domain.com", "password");

Claus Konrad said...

var client = ...: Instantiation of a new client object. The arguments passed here are dropbox specific keys to identity your client applicication to Dropbox(NOT you as a user!)

clint.login(...): To authenticate yourself to dropbox.

Rahul Das said...

How do we download a file from dropbox using .net

And when we upload does it generate any link?

ttitto said...

client.Login("...", "..."); is no longer supported in the last version of DropNet. How is it replaced?

Pavan Shevle said...


Anonymous said...

Always return BadRequest...Help

Anonymous said...

same here, bad request.
any help?

iPhone/XCode - not all cases are equal!

This bit me! Having made some changes to an iPhone application (Obj-C); everything worked fine in the simulator. But, when deploying the s...