Skip to content

Instantly share code, notes, and snippets.

@oneEyedSunday
Created December 21, 2020 06:40
Show Gist options
  • Save oneEyedSunday/e931e708fe4bce6e6294f37a93546395 to your computer and use it in GitHub Desktop.
Save oneEyedSunday/e931e708fe4bce6e6294f37a93546395 to your computer and use it in GitHub Desktop.
Download individual files from a shared dropbox folder
using System;
using System.IO;
using System.Net;
using System.ComponentModel;
using Dropbox.Api;
using System.Threading.Tasks;
using Dropbox.Api.Files;
using System.Linq;
namespace DropboxDownload
{
class Program
{
public static async Task Main()
{
try
{
//string path = "/fe59ayfudevlknc/20201212_import_images.zip";
DropboxClient dropboxClient = new DropboxClient("ACCESSTOKEN"); // needs sharing.read, file.read, etc
//var es = await ListFolder(dropboxClient, path);
//dropboxClient.Files.ListFolderAsync()
//var sharedUrl = "https://www.dropbox.com/sh/fe59ayfudevlknc/20201212_import_images.zip?dl=0";
var sharedUrl = "https://www.dropbox.com/sh/8ad2w9md863u2nq/AAAqgMAGaKqo6u1tD_3tDev3a?dl=1";
//var sharedLink = new SharedLink("https://www.dropbox.com/s/fe59ayfudevlknc/20201212_import_images.zip?dl=0");
//var sharedLink = new SharedLink("https://www.dropbox.com/sh/1rejgsznpfqlpoo/AABrEyAzUMYD0uAyHA6_yaO-a?dl=0");
var sharedLink = new SharedLink(sharedUrl);
var sharedFiles = await dropboxClient.Files.ListFolderAsync(path: "", sharedLink: sharedLink);
foreach (var file in sharedFiles.Entries)
{
if (file.IsFile)
{
using (var response = await dropboxClient.Sharing.GetSharedLinkFileAsync(url: sharedUrl, path: "/" + file.Name))
{
var stream = await response.GetContentAsStreamAsync();
using (var fs = File.Open(file.Name, FileMode.OpenOrCreate))
{
stream.CopyTo(fs);
}
}
}
}
} catch (Exception ex)
{
Console.WriteLine($"Omo yawa dey: {ex.Message}");
}
}
}
@oneEyedSunday
Copy link
Author

This took way too long to figure out :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment