One month down in 2025: How are your resolutions coming along? Check out how to get back on track here.
Forum Discussion
Bobby I
5 years agoExplorer | Level 4
Download any file as a Stream using C# SDK
Hey, I'm wanting to download a file through the C# SDK, however I'm having issues when it is of the Dropbox .paper or similar cloud storage file type. I'm wanting it as a MemoryStream for my team and I to work with. Using the DropboxClient.Files.DownloadAsync, I'm given an Unsupported Type error when attempting to download a .paper / .gdoc etc, but works fine with .doc / .docx. I'm given a similar error when using the DownloadZipAsync. I saw in the docs to use Export As. Inspecting the FileMetaData.ExportInfo only contained "html" for the .paper file I was trying to download. I've looked online for a solution but am coming up empty handed. Here is a snippet of my code.
string path = myInputs.path; MemoryStream newStream = new MemoryStream(); try { var fileObject = await dropboxClient.Files.GetMetadataAsync(path); if (!String.IsNullOrWhiteSpace(fileObject.AsFile.ExportInfo.ExportAs)) { using (var response = await dropboxClient.Files.ExportAsync(fileObject.PathLower)) { (await response.GetContentAsStreamAsync()).CopyTo(newStream); return newStream; } } else using(var response = await dropboxClient.Files.DownloadAsync(path)){ (await response.GetContentAsStreamAsync()).CopyTo(newStream); return newStream; } }
What's the best way to handle universally downloading files from dropbox, regardless of file type? I would prefer to not call GetMetaDataAsync if possible to lower API calls, but it's okay if it required for checking the ExportInfo.
No, unfortunately the API doesn't offer the ability to request a different export type, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though.
- Greg-DB
Dropbox Staff
You have the right idea here. As you found, some cloud files, such as Paper docs, can't be downloaded via the normal Download method. You need to use Export for those instead.
You can either just try to Download the file and catch the UnsupportedFile error, at which point you would use Export instead, or you can check the file ahead of time by calling GetMetadata like you mentioned. If you do that though, you can use FileMetadata.IsDownloadable instead of checking ExportAs.
- Bobby IExplorer | Level 4
I see. I think I will add a catch for this as you suggested and then attempt to export it. When I was attempting to export a paper file, the ExportAs value was always html. Through the Dropbox GUI, we're able to export as Markdown, Docx, or PDF. Is it possible to change how we want it to be exported programmatically? When it is html, we get a lot of extra fluff like styling and tags, when all we are realy interested in is the content.
- Greg-DB
Dropbox Staff
No, unfortunately the API doesn't offer the ability to request a different export type, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,950 PostsLatest Activity: 2 days ago
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!