2011-12-04 50 views
0

是否有将图像从.net Image Control保存到服务器目录的方法?将图像从Image.Control保存到网站目录

这是大干快上的Page_Load生成的条码图像:

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

条形码图像显示的只是正常的网页,但我wnated将其保存到一个目录以及:

~/barcode image/TEST.jpg


到目前为止,这是我有:

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); 

但它给我一个错误:Illegal characters in path.

回答

1

WebClient需要一个Web地址远程参数 - 你给它一个本地路径此参数。

此外Server.MapPath需要一个适当的目录 - 不是..

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); 
+0

oded - 我应该硬编码吗? @“http:// localhost ...因为我得到一个错误:在一个WebClient请求期间发生异常 –

+0

@PodMays - 我不知道你的web服务器的名字,而是你可以从Http头获得它。 – Oded

+0

oded我能够通过路径:'remote = @“http://”+ Request.Url.Authority.ToString()+ @“/ app/BarCode.aspx?code = TEST”'但它仍然给我发现错误在WebClient请求期间发生异常 –