We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Ilya_C
8 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 ?
3 Replies
- chirstius8 years ago
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
- eduapp8 years agoNew 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-DB8 years ago
Dropbox Community Moderator
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.
Thanks!
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!