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?

1

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.