Friday, 13 April 2012

Downloading Images from external url


string imgFullPath = "https://www.google.co.in/images/srpr/logo3w.png";

//get the full path 

string FileName = Path.GetFileNameWithoutExtension(imgFullPath) + Path.GetExtension(imgFullPath);

//if you want you can download image in your desired extension 


WebClient wc = new WebClient();

wc.DownloadFile(imgFullPath, Server.MapPath("~/images/temp/") + FileName);

//download the file in images location


FileStream fs = new FileStream(Server.MapPath("~/images/temp/" + FileName), FileMode.Open, FileAccess.Read, FileShare.Read);

//get the image in file stream


System.Drawing.Image nwImage = System.Drawing.Image.FromStream(fs);

//Now using this nwImage you can resize the image 


nwImage.Save(Server.MapPath("~/images/") + "your_own_image_name.extension");

File.Delete(Server.MapPath("~/images/temp/" + FileName));

//if no needed the original image delete the file using this



Tages: Downloading images from external url, resizing root folder images, downloading images from path,

No comments:

Post a Comment

Parsing JSON w/ @ symbol in it

To read the json response like bellow @ concatenated with attribute                             '{ "@id": 1001, "@name&q...