将图像文件从url复制到本地文件夹?

我有一个图片的url。 例如“ http://sofzh.miximages.com/c%23/abc.jpg ”。 我希望将本地文件夹中的URL复制到“c:\ images \”; 当我将该文件复制到文件夹中时,我必须将图像重命名为“c:\ images \ xyz.jpg”。

我们怎么能这样做?

请求图像,然后保存。 例如:

byte[] data; using (WebClient client = new WebClient()) { data = client.DownloadData("http://sofzh.miximages.com/c%23/abc.jpg"); } File.WriteAllBytes(@"c:\images\xyz.jpg", data); 

您可以使用WebClient

 using (WebClient wc = new WebClient()) wc.DownloadFile("http://sofzh.miximages.com/c%23/abc.jpg", @"c:\images\xyz.jpg"); 

这假设您实际上具有C:\images文件夹的写权限。

那并不太难。 打开WebCLient并抓取位,将它们保存在本地….

 using ( WebClient webClient = new WebClient() ) { using (Stream stream = webClient.OpenRead(imgeUri)) { using (Bitmap bitmap = new Bitmap(stream)) { stream.Flush(); stream.Close(); bitmap.Save(saveto); } } } 
 string path = "~/image/"; string picture = "Your picture name with extention"; path = Path.Combine(Server.MapPath(path), picture); using (WebClient wc = new WebClient()) { wc.DownloadFile("http://sofzh.miximages.com/c%23/abc.jpg", path); } 

它适合我