0
if (FileExtension == ".txt")
{
    string enumLines = File.ReadAllText(FoundPics, Encoding.UTF8);
    Clipboard.SetText(enumLines);
    using (WebClient client = new())
    {
        DirectoryInfo di = new DirectoryInfo(FoundPics);
        client.DownloadFile(enumLines, FolderPath + @"\" + "Template.gif");
        Image gifTemplate = Image.FromFile(FolderPath + @"\" + "Template.gif");
        pictureBox.Image = gifTemplate;
    }
}

I have this code that retrieves a url from a txt file, downloads a .gif from it and sets it to the picturebox However it's using Webclient that I was recommended to avoid. I'm trying to change to HTTPClient now but I'm really lost. Can someone provide some pseudo code so that I can figure out what to do?

MD. RAKIB HASAN
  • 3,670
  • 4
  • 22
  • 35
  • 1
    Does this answer your question? [Download file with WebClient or HttpClient?](https://stackoverflow.com/questions/45711428/download-file-with-webclient-or-httpclient) – MD. RAKIB HASAN Jan 23 '23 at 13:38

1 Answers1

1
var data  = await client.GetByteArrayAsync(FolderPath + @"\" + "Template.gif");
File.WriteAllBytes(@"\path\to\downloads\Template.gif", data);
  1. FolderPath must be a uri
  2. Your application must have write access to the downloads folder
Mayank Sinha
  • 158
  • 6