下载图片 找到的demo 记录一下 以供以后参考使用
string fileurl = "www.xxx.com/xxxxx.png";
Console.WriteLine(fileurl);
//图片保存的地址,自动换成相应的路径
string fileName = System.IO.Path.GetFileName(fileurl);
string path = 你保存的路径;
path = path.Replace(fileName, "").Replace("/", "\\");
bool exists = System.IO.Directory.Exists(path);
if (!exists) System.IO.Directory.CreateDirectory(path);
//下载
System.Net.WebClient wc = new System.Net.WebClient();
HttpWebRequest webrequ = (HttpWebRequest)WebRequest.Create(fileurl);
WebClient client = new WebClient();
byte[] bytes = client.DownloadData(new Uri(fileurl));
MemoryStream ms = new MemoryStream(bytes);
ms.Seek(0, SeekOrigin.Begin);
Console.WriteLine("开始下载-----------");
ms.WriteTo(new FileStream(path + fileName, FileMode.OpenOrCreate));
Console.WriteLine(path + fileName);
}
}