C#
C#

help

Root Question Message

edcelmare
edcelmare12/21/2022
❔ 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.
Angius
Angius12/21/2022
Don't use WebClient
Angius
Angius12/21/2022
Use HttpClient
Angius
Angius12/21/2022
Download bytes, then use a filestream to write those bytes to a file
TheRanger
TheRanger12/21/2022
heres an example
TheRanger
TheRanger12/21/2022
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
Angius12/21/2022
Doesn't even need the Uri tbh
TheRanger
TheRanger12/21/2022
the one with the string parameter creates a uri anyway
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy