Unboxing Dropbox and SharpBox

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

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:

    1. Create a new Dropbox account at www.dropbox.com/login#register
    2. Accept the Dropbox App Developer terms at www.dropbox.com/developers/apply
    3. Continue with the next step, where you create an app with a suitable test name and a short nonsense description

dropboxpost1 300x222 Unboxing Dropbox and SharpBox
The Dropbox admin interface should now show you the App Key and App Secret you need later for creating a security token file.

SharpBox

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.” – harpbox.codeplex.com

Follow these steps to set up a test application in Visual Studio 2010 and include Sharpbox in it:

    1. Create a new C# Console Application in Visual Studio
    2. Open the properties of the application and set Target Framework to .NET Framework 4
    3. Add the SharpBox NuGet package named  AppLimit.CloudComputing.SharpBox
    4. Open the File Explorer and start the SharpBox tool DropBoxTokenIssuer.exe located in the folder approotpackagesAppLimit.CloudComputing.SharpBox.1.2.0.542libnet40-full. This tool is used to create a Security Token file you will use in your application.
    5. Enter the Application Key and Application Secret you previously got in the Dropbox admin interface. Name the file DropBoxToken and finally click the Authorize button.

 

dropboxpost2 300x158 Unboxing Dropbox and SharpBox

 

This will hopefully lead you to the Dropbox login page, where you will use the login credentials for the account you previously created. (Please make sure you set the Target Framework correctly to .Net Framework 4 if no login page appears.)

If everything worked out correctly, you will now see an error page. Confusing? This is because the Sharpbox tool redirects to a page that does not exist on Codeplex. You will find the Security Token file created in the same folder where the tool application exists.

Finally, move this Security Token file to C:Test together with an empty text file you create and name texttest.txt.

The code

Everything is now set up for some coding. Fill the Program.cs with this:

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.

Useful Hints and Links

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:

 

3 Comments

  • srinivas on Nov 01, 2012 Reply

    hi,
    iam using the tool smae what you have mention i am unble to getting my accesstoken what i have done, down loaded latest sharpbox dll to communicate to dropbox this is url http://sharpbox.codeplex.com/releases/view/74634 after running the exe file i am able to login into the my dropbox account and also able to click on allow button after it i am getting http 500 error web page is not ailable some

    • Silver on Nov 01, 2012 Reply

      Hi,
      The blog post explains this here:

      “This will hopefully lead you to the Dropbox login page, where you will use the login credentials for the account you previously created. (Please make sure you set the Target Framework correctly to .Net Framework 4 if no login page appears.)
      If everything worked out correctly, you will now see an error page. Confusing? This is because the Sharpbox tool redirects to a page that does not exist on Codeplex. You will find the Security Token file created in the same folder where the tool application exists.”

  • Yash on Feb 23, 2012 Reply

    Wow what anice and clear code !!!
    Thanks dude !!!!

Leave ReplyLeave a Reply to Yash

Cancel Reply