Here what i came up with..
public string getImgFrmUrl(string url,string PartialDstntnPath ="/Content/img/Layout/")
{
var tmpP = PartialDstntnPath;
var imgPath = System.Web.HttpContext.Current.Server.MapPath(tmpP);
var name = Guid.NewGuid();
var fileExt = Path.GetExtension(url);
using (WebClient webClient = new WebClient())
{
const SslProtocols _Tls12 = (SslProtocols)0x00000C00;
const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12;
ServicePointManager.SecurityProtocol = Tls12;
try
{
byte[] data = webClient.DownloadData(url);
using (MemoryStream mem = new MemoryStream(data))
{
using (var yourImage = Image.FromStream(mem))
{
if (fileExt.ToLower() == ".png")
{
yourImage.Save(imgPath + name + fileExt, ImageFormat.Png);
}
else
{
yourImage.Save(imgPath + name + fileExt, ImageFormat.Jpeg);
}
}
}
}
catch (Exception ex){
return ex.Message;
}
}
return tmpP + name + fileExt;
}