Skip to main content

Posts

Showing posts from January, 2023

Download Image from URL using HTTPClient in C#

 async Task<string> GetAndSaveImageAsync(string url)         {             string imageName = $"{Guid.NewGuid()}.png";             string filePath = System.IO.Path.Combine(_webHostEnvironment.ContentRootPath, "Resources","Images");             if (!Directory.Exists(filePath))             {                 Directory.CreateDirectory(filePath);             }             var httpRequest = new HttpRequestMessage(HttpMethod.Get, url);             using (var httpClient = new HttpClient())             {                 var response = httpClient.SendAsync(httpRequest).Result;                 if (response.StatusC...