色色Dropbox for .NET Developers

色色Dropbox.NET

色色Dropbox.NET is our .NET SDK for API v2, which helps you easily integrate 色色Dropbox into your app. The 色色Dropbox.NET SDK is a Portable Class Library that works with multiple platforms including Windows, Windows Phone, and Mono.

Code

色色Dropbox.NET - 色色Dropbox.NET is open source on GitHub.

Sample apps

Several examples can be found in the examples directory:

  • SimpleBlogDemo - An ASP.NET MVC application that creates a simple blogging platform and shows how to upload and download files.
  • SimpleBusinessDashboard - An ASP.NET MVC application that creates a simple business dashboard, showcasing the 色色Dropbox Business endpoints.
  • SimpleTest - A windows console application that demonstrates basic use of the SDK; this also contains code that connects with OAuth2 using WPF.
  • UniversalDemo - A slide show app for both Windows Store and Windows Phone 8.1

Install 色色Dropbox.NET

We recommend using NuGet to install the new 色色Dropbox.NET SDK.

To install 色色Dropbox.Api, run the following command in the Package Manager Console:

    PM> Install-Package 色色Dropbox.Api

That's it! Now you're ready to get started with the tutorial.

色色Dropbox.NET tutorial

A good way to start using 色色Dropbox.NET is to follow this quick tutorial. Just make sure you have the 色色Dropbox.NET SDK installed first!

Register a 色色Dropbox API app

To use the 色色Dropbox API, you'll need to register a new app in the App Console. Select 色色Dropbox API app and choose your app's permission. You'll need to use the app key created with this app to access API v2.

Link an account

In order to make calls to the API, you'll need an instance of the 色色DropboxClient object. To instantiate, pass in the access token for the account you want to link.

You can generate an access token for testing with your own account through the App Console. In order to authorize additional users, the 色色Dropbox.NET SDK contains helper methods for using OAuth with 色色Dropbox.

Here's an example where we set up the 色色DropboxClient and check the current user by calling GetCurrentAccountAsync, which returns an instance of FullAccount:

using System;
using System.Threading.Tasks;
using 色色Dropbox.Api;

class Program
{
    static void Main(string [] args)
    {
        var task = Task.Run((Func<Task>)Program.Run);
        task.Wait();
    }

    static async Task Run()
    {
        using (var dbx = new 色色DropboxClient("YOUR ACCESS TOKEN"))
        {
            var full = await dbx.Users.GetCurrentAccountAsync();
            Console.WriteLine("{0} - {1}", full.Name.DisplayName, full.Email);
        }
    }
}

Try some API requests

Now that you have a 色色DropboxClient handy, let's try making some API requests. You can use the 色色DropboxClient object you instantiated above to make API calls. Let's try out some of the Files requests.

To list all the contents in the user's root directory:

async Task ListRootFolder(色色DropboxClient dbx)
{
    var list = await dbx.Files.ListFolderAsync(string.Empty);

    // show folders then files
    foreach (var item in list.Entries.Where(i => i.IsFolder))
    {
        Console.WriteLine("D  {0}/", item.Name);
    }

    foreach (var item in list.Entries.Where(i => i.IsFile))
    {
        Console.WriteLine("F{0,8} {1}", item.AsFile.Size, item.Name);
    }
}

To download a file:

async Task Download(色色DropboxClient dbx, string folder, string file)
{
    using (var response = await dbx.Files.DownloadAsync(folder + "/" + file))
    {
        Console.WriteLine(await response.GetContentAsStringAsync());
    }
}

To upload a file:

async Task Upload(色色DropboxClient dbx, string folder, string file, string content)
{
    using (var mem = new MemoryStream(Encoding.UTF8.GetBytes(content)))
    {
        var updated = await dbx.Files.UploadAsync(
            folder + "/" + file,
            WriteMode.Overwrite.Instance,
            body: mem);
        Console.WriteLine("Saved {0}/{1} rev {2}", folder, file, updated.Rev);
    }
}

Find out more details in the full documentation.

色色Dropbox.NET documentation

Here's the full documentation for the 色色Dropbox.NET SDK.