Unboxing Dropbox and SharpBox

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

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
    image

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.” – sharpbox.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 DropBoxTokenand finally click the Authorize button.image
  6. 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.)
  7. 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.
  8. 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:

/Johan
codeblog.silfversparre.com

 

Token problems

2012-12-10

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

/Johan

18 Comments

  1. Yash

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

  2. srinivas

    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

    • 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.”

      • srinivas

        Hi

        Thanks for you immediate replay what i am doing is tring with one console from this url https://sharpbox.codeplex.com/wikipage?title=SharpBox%20Developer%20Tutorials&referringTitle=Documentation what is doing same like you, i have downloaded the latest dll from this sitel https://sharpbox.codeplex.com/releases/view/74634 what that file contails dll related to .net 3.5 and 4.0 the tool TokenIssuegenerator.exe is available in 4.0 may be (console) appliaction run both 3.5 and 4.0 i amde target frame work of my console application is on 3.5 bcoz i need to integrate this into sharepoint as web part sharepoint2010 will allow .net3.5 framework only that is the reason i made console application build options as 3.5 runnning the tokenissuegenerator .exe to get the accesstoken file after running this exe i am did not file any accesstoken file will you please what is issue with tokengenerator

      • Akki

        DropBoxTokenIssuer does not create any token files in tool’s folder when I click “Allow” and shows HTTP:500. What I’m doing wrong?

  3. srinivas

    hi,
    i am able to build my console application even i made target framework to .net3.5 bcoz i need to integrate in sharepoint2010 from Sharepoint interface itself i need to perform CRUD Actions, dropboxTokenIssue.exe will not giving to me nay out put file i am running dropboxtokenIssuer.exe dll from this https://sharpbox.codeplex.com/releases/view/74634

  4. ts

    hi,

    The program DropBoxTokenIssuer.exe has stopped working for some reason. I used to generate token files succesfully about a month back, but now after I login and press Allow, it gives an HTTP500 error. Any idea why is this happening? Is there any other way to generate these token files?

    • Yes, it seems to be a problem with the tool. I can see Srinivas cross posted his questions to Sharpbox forum at http://sharpbox.codeplex.com/discussions without any response. Try to contact one of the developers of the SharpBox project. Atleast one of them seem to still be active on CodePlex.

    • srinivas

      Hi,
      Did any one find the Dropboxtokenissuer.exe tool issue. web page http 500 error is fine bcoz they provided some invalid url, but using the dropboxtokenissue.exe tool i am not getting the any accesstoken file in respective folder where the tool is avilable, can any one fix this issue plese suggest me how to fix it

  5. subbu

    is this console application code will run without asking the user to login his dropbox acount what i mean whithout building the authentication url

  6. JUAN

    Hey what i should do if i dont find that AccesToken in the file ! ????? i am doing all what the tutorial says but no ACCes TOken generated!!!! what is wrong ??

  7. Buddhi

    For answer please refer following URL…

    http://sharpbox.codeplex.com/workitem/18848

  8. Debbie

    Hi do u have a working sample in WPF for your codes above?

  9. hamid reza

    Error http 500 in DropBoxTokenIssuer solve by this program
    copy sharpzip dll side in file
    http://sharpbox.codeplex.com/workitem/18848

  10. Giovanni

    Hi!

    “Couldn’t retrieve child elements from the server”

    the erros occurs in:

    test token (DropBoxTokenIssuer.exe)

    or in .Open method:

    Dim storageToken = dropBoxStorage.Open(dropBoxConfig, accessToken)

    the link: http://stackoverflow.com/questions/9870751/uploading-to-dropbox-using-sharpbox-api
    did’nt help.

    my app in drop box is: Permission typeFull Dropbox

    any idea? thanks.

Leave a Reply