Pod Mays
Pod Mays

Reputation: 2583

Save image from Image.Control to website directory

Is there a way to save an image from a .net Image Control to the server's directory?

It's a barcode image that gets generated on Page_Load:

Image1.ImageUrl = "~/app/barcode.aspx?code=TEST"

The barcode image displays just fine on the webpage, but I wnated to save it to a directory as well:

~/barcode image/TEST.jpg


So far, here's what I have:

WebClient webClient = new WebClient();
string remote = Server.MapPath("..") + @"\app\barcode.aspx?code=TEST";
string local = Server.MapPath("..") + @"\barcode image\TEST.jpg";
webClient.DownloadFile(remote, local);

But it gives me an error: Illegal characters in path.

Upvotes: 0

Views: 2170

Answers (1)

Oded
Oded

Reputation: 499002

WebClient requires a web address for the remote parameter - you are giving it a local path for this parameter.

Additionally Server.MapPath expects a proper directory - not ...

WebClient webClient = new WebClient();
string remote = @"http://localhost/app/barcode.aspx?code=TEST";
string local = Server.MapPath("barcode image/TEST.jpg");
webClient.DownloadFile(remote, local);

Upvotes: 1

Related Questions