Skip to main content

Posts

Showing posts from 2023

Limit Upload File Type Extensions ASP.NET MVC 5

  //-----------------------------------------------------------------------    // <copyright file="AllowExtensionsAttribute.cs" company="None">    //     Copyright (c) Allow to distribute this code and utilize this code for personal or commercial purpose.    // </copyright>    // <author>Asma Khalid</author>    //-----------------------------------------------------------------------       namespace  ImgExtLimit.Helper_Code.Common   {        using  System;        using  System.Collections.Generic;        using  System.ComponentModel.DataAnnotations;        using  System.Linq;      ...

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...