[英]Unable to save image from URL in C# - using Webclient and DownloadFile();
I am unable to download images from an RSS Feed, where the URL doesn't contain a filename. 我无法从RSS Feed中下载图像,其中URL不包含文件名。
Example - 范例-
Image URL I would like to download (it works if you click on it in a browser, but in code it doesn't work): 我要下载的图片网址(如果您在浏览器中单击该图片网址,它将起作用,但是在代码中,该网址不起作用):
http://www.deviantart.com/download/286471805/ http://www.deviantart.com/download/286471805/
Using the code below I get a "An exception occurred during a WebClient request." 使用下面的代码,我得到“ WebClient请求期间发生异常”。 error.
错误。 I have no idea why this isn't working.
我不知道为什么这不起作用。
Any ideas on how I can save these files? 关于如何保存这些文件的任何想法?
private void Start_Button_Click(object sender, EventArgs e)
{
WebClient MyDownloader = new WebClient();
MyDownloader.DownloadFile(@"http://www.deviantart.com/download/286471805/", @"c:\test\");
}
You have to specify a file name as the second argument, not the download directory: 您必须指定文件名作为第二个参数,而不是下载目录:
using (var client = new WebClient())
{
client.DownloadFile("http://www.deviantart.com/download/174633066/",
@"c:\test\file.png");
} ↑
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.