One month down in 2025: How are your resolutions coming along? Check out how to get back on track here.
Forum Discussion
Ilya_C
7 years agoExplorer | Level 3
Download file to local dir
Hello! I try to Download to disc one file from cloud. I use Dropbox .Net SDK C#. Here my code :
static async Task Download(string folder, string file) { var dbx = new DropboxClient("TOKEN"); using (var response = await dbx.Files.DownloadAsync(folder + "/" + file)) { if (response != null) Console.WriteLine("Download start - {0}", response.Response.Name); else { Console.WriteLine("file not found"); } var files = await response.GetContentAsStreamAsync(); using (FileStream fileStream = File.Create(response.Response.Name, (int)files.Length)) { byte[] data = new byte[files.Length]; files.Read(data, 0, (int)data.Length); fileStream.Write(data, 0, data.Length); } Console.WriteLine("file was Downloaded"); } }
I have `Download start ` but never get `file was Downloaded`, why ?
- chirstius
Dropbox Staff
Hello Ilya_C,
I think part of the problem is in this line:
using (FileStream fileStream = File.Create(response.Response.Name, (int)files.Length))
The stream returned is not seekable, and I think getting the Length requires a seek operation. Can you try removing that and seeing if things work as expected?
Also, you might be able to eliminate some code by using CopyTo():
using (FileStream fileStream = File.Create(response.Response.Name)) { files.CopyTo(fileStream); }
Let me know if that helps,
-Chuck
- eduappNew member | Level 2
Guys help, I did generate a link to my pdf file, and recently tried to access it from my Android App, using Asynch Task, but it returns nothing and crashes my App so bad. It seems like my App cannot catch the file dropped in my dropbox folder. Note. I can easily download all pdf files from any online source without having an issue. It sucks....please help me..how am i supposed to it?
- Greg-DB
Dropbox Staff
eduapp Your question looks unrelated to this thread, so please start a new thread with the details of the issue you're seeing (e.g., steps and code to reproduce the issue, plus the error message for the crash) so we can take a look and help without spamming anyone else here:
https://www.dropboxforum.com/t5/forums/postpage/board-id/101000014
Thanks!
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,941 PostsLatest Activity: 4 hours 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!