❔ Problem with downloading on hard drive

Whenever I try to use webclient.DownloadFileAsync("myurl", "the path on my hard disk"), it creates a 0 zero bytes file.
5 Replies
Angius
Angius2y ago
Don't use WebClient Use HttpClient Download bytes, then use a filestream to write those bytes to a file
TheRanger
TheRanger2y ago
heres an example
var uri = new Uri("myurl");
HttpClient client = new HttpClient();
var response = await client.GetAsync(uri);
await using var fs = new FileStream(path, FileMode.CreateNew);
await response.Content.CopyToAsync(fs);
var uri = new Uri("myurl");
HttpClient client = new HttpClient();
var response = await client.GetAsync(uri);
await using var fs = new FileStream(path, FileMode.CreateNew);
await response.Content.CopyToAsync(fs);
Angius
Angius2y ago
Doesn't even need the Uri tbh
TheRanger
TheRanger2y ago
the one with the string parameter creates a uri anyway
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server