Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
sanjayssk
9 years agoHelpful | Level 6
Need .Net sample for download to file
I'm using Dropbox API in an asp.net application. I have managed to download the file contents into a stream upto the following line of code in an async task.
var strm = response.GetContentAsStreamAsync();
But I can't find a sample of how to write this stream finally to a file on the web server for which I do have a path DestPath. I have tried using some .Net code to write Stream to file but that complains and can not compile because the above strm and IO.Stream are different. I can't find a sample in .Net SDK for dropbox. Can someone help?
The GetContentAsStream method yields a Stream, so you should be able to use CopyTo like this:
var strm = await response.GetContentAsStreamAsync(); using (var fileStream = File.Create(localFilePath)) { strm.CopyTo(fileStream); }
8 Replies
Replies have been turned off for this discussion
- Greg-DB9 years ago
Dropbox Community Moderator
The GetContentAsStream method yields a Stream, so you should be able to use CopyTo like this:
var strm = await response.GetContentAsStreamAsync(); using (var fileStream = File.Create(localFilePath)) { strm.CopyTo(fileStream); } - sanjayssk9 years agoHelpful | Level 6
Thanks for the speedy reply! I was missing the "await" and hence it was complaining that CopyTo is not a method of Task<Stream>.
- sanjayssk9 years agoHelpful | Level 6
Any ideas how to catch a Timeout exception for large downloads? I tried using Try/Catch but it is not raised.
Update: I tried this code but it doesn't cause a timeout.
var expirationTimeTask = Task.Delay(TimeSpan.FromSeconds(30)); var strm = response.GetContentAsStreamAsync(); var finishedTask = await Task.WhenAny(expirationTimeTask, strm); if (finishedTask == expirationTimeTask) { //timeout error processing (does not get here) } - sanjayssk9 years agoHelpful | Level 6
Oops. On debugging, I found that it is stuck at CopyTo and that takes a long time and times out. So does the actual download occur on "CopyTo"?
Update: Was above to solve this by studying the Asp.net samples on:
- yasirjaseem7 years agoNew member | Level 2
How to call it on windows/desktop application to download file.
- Greg-DB7 years ago
Dropbox Community Moderator
yasirjaseem We recommend using the official Dropbox .NET SDK. There's an example of downloading files here. If something isn't working as expected for you, open a new thread with details.
- kelly03185 years agoNew member | Level 2
i am tring to downlaod a maual but it will not work
- Greg-DB5 years ago
Dropbox Community Moderator
kelly0318 This is an old thread about writing code to download from Dropbox programmatically. If you need help using Dropbox itself you may want to open a thread in the 'Help from the Community > Files & folders' section or otherwise contact support.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
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, Facebook or Instagram.
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!