Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy image file from web url to local folder?

Tags:

c#

asp.net

vb.net

I have a web URL for the image. For example "http://testsite.com/web/abc.jpg". I want copy that URL in my local folder in "c:\images\"; and also when I copy that file into folder, I have to rename the image to "c:\images\xyz.jpg".

How can we do that?

like image 643
James123 Avatar asked Apr 28 '11 19:04

James123


2 Answers

Request the image, and save it. For example:

byte[] data;
using (WebClient client = new WebClient()) {
  data = client.DownloadData("http://testsite.com/web/abc.jpg");
}
File.WriteAllBytes(@"c:\images\xyz.jpg", data);
like image 122
Guffa Avatar answered Nov 15 '22 17:11

Guffa


You could use a WebClient:

using (WebClient wc = new WebClient())
    wc.DownloadFile("http://testsite.com/web/abc.jpg", @"c:\images\xyz.jpg");

This assumes you actually have write rights to the C:\images folder.

like image 45
BrokenGlass Avatar answered Nov 15 '22 17:11

BrokenGlass