Skip to content

darocha/DropboxRestAPI

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DropboxRestAPI

About

DropboxRestAPI is a C# client for the Dropbox service through its RESTful API.

DropboxRestAPI aims towards being the most comprehensive implementation for the Dropbox REST API in .Net/C#.

Features

Contact

You can contact me on twitter @saguiitay.

NuGet

DropboxRestAPI is available as a NuGet package

Release Notes

  • 1.2.1 Added support for the Business Group Info endpoint.
  • 1.2.0 Fixed SharedFolder methods. Breaking Changes:
    • Authorize is no longer an async method
    • Split SharedFolders method into two methods SharedFolders and SharedFolder
  • 1.1.8 Added some fields to account information. Added support for groups in SharedFolder.
  • 1.1.7 Improved handling of cancellation tokens.
  • 1.1.6 Fixed usage of SaveUrlJobAsync. Memory/Performance improvements.
  • 1.0.5 Fixed usage of 'cursor' parameter. Added support for SharedFolder information.
  • 1.0.5 Fixed usage of 'cursor' parameter. Added support for SharedFolder information.
  • 1.0.4 Fixed issues with downloading of large files.
  • 1.0.3 Fixed issues with downloading of zero-bytes files.
  • 1.0.0 Initial release.

Usage

var options = new Options
    {
        ClientId = "...",
        ClientSecret = "...",
        RedirectUri = "..."
    };

// Initialize a new Client (without an AccessToken)
var client = new Client(options);

// Get the OAuth Request Url
var authRequestUrl = await client.Core.OAuth2.AuthorizeAsync("code");

// TODO: Navigate to authRequestUrl using the browser, and retrieve the Authorization Code from the response
var authCode = "...";

// Exchange the Authorization Code with Access/Refresh tokens
var token = await client.Core.OAuth2.TokenAsync(authCode);

// Get account info
var accountInfo = await client.Core.Accounts.AccountInfoAsync();
Console.WriteLine("Uid: " + accountInfo.uid);
Console.WriteLine("Display_name: " + accountInfo.display_name);
Console.WriteLine("Email: " + accountInfo.email);

// Get root folder without content
var rootFolder = await client.Core.Metadata.MetadataAsync("/", list: false);
Console.WriteLine("Root Folder: {0} (Id: {1})", rootFolder.Name, rootFolder.path);

// Get root folder with content
rootFolder = await client.Core.Metadata.MetadataAsync("/", list: true);
foreach (var folder in rootFolder.contents)
{
    Console.WriteLine(" -> {0}: {1} (Id: {2})", 
        folder.is_dir ? "Folder" : "File", folder.Name, folder.path);
}

// Initialize a new Client (with an AccessToken)
var client2 = new Client(options);

// Create a new folder
var newFolder = await client2.Core.FileOperations.CreateFolderAsync("/New Folder");

// Find a file in the root folder
var file = rootFolder.contents.FirstOrDefault(x => x.is_dir == false);

// Download a file
var tempFile = Path.GetTempFileName();
using (var fileStream = System.IO.File.OpenWrite(tempFile))
{
    await client2.Core.Metadata.FilesAsync(file.path, fileStream);
}

//Upload the downloaded file to the new folder

using (var fileStream = System.IO.File.OpenRead(tempFile))
{
    var uploadedFile =await client2.Core.Metadata.FilesPutAsync(fileStream, newFolder.path + "/" + file.Name);
}

// Search file based on name
var searchResults = await client2.Core.Metadata.SearchAsync("/", file.Name);
foreach (var searchResult in searchResults)
{
    Console.WriteLine("Found: " + searchResult.path);
}

About

Dropbox REST API client in C#

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 84.2%
  • PowerShell 15.7%
  • Batchfile 0.1%