0

I'm using .Net 4.5 version for this C# project and successfully Implementing a Download using this Code (taken from zetcode):

Program.cs

using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

namespace HttpClientDownloadImage
{
    class Program
    {
        static async Task Main(string[] args)
        {
            using var httpClient = new HttpClient();
            var url = "http://webcode.me/favicon.ico";
            byte[] imageBytes = await httpClient.GetByteArrayAsync(url);

            string documentsPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);

            string localFilename = "favicon.ico";
            string localPath = Path.Combine(documentsPath, localFilename);
            File.WriteAllBytes(localPath, imageBytes);
        }
    }
}
  • 1st Problem is : no way to implement percentage 0% until 100% from the async call. From File.WriteAllBytes() how to show the progress out into ant (int/double) variable or something?

  • 2nd Problem is: when I checked on nu package manager, for the Library of System.Net.Http but the versioning is strange. Look at the number shown! It's not matched! 4.3.4 and 4.0.0 What is that?

version

gumuruh
  • 2,544
  • 4
  • 33
  • 56
  • Related: [Progress bar with HttpClient](https://stackoverflow.com/questions/20661652/progress-bar-with-httpclient) – Theodor Zoulias Mar 26 '20 at 00:05
  • Looked at a bunch of posts, not saying any of these work, as I've not tested. https://stackoverflow.com/questions/20661652/progress-bar-with-httpclient (3rd answer seemed promising). HttpClient Progress extension - https://gist.github.com/dalexsoto/9fd3c5bdbe9f61a717d47c5843384d11. Have you looked at using `WebClient` instead of `HttpClient`? – Rob Scott Mar 26 '20 at 00:32
  • sure but your suggestion is by using System.Web instead of System.Net implementation of httpclient. – gumuruh Mar 26 '20 at 03:20
  • what about the versioning.... coz it's still the same case. – gumuruh Mar 26 '20 at 08:50

0 Answers0