【问题标题】:Unable to save image from URL in C# - using Webclient and DownloadFile();无法从 C# 中的 URL 保存图像 - 使用 Webclient 和 DownloadFile();
【发布时间】:2012-05-18 05:25:33
【问题描述】:

我无法从 URL 不包含文件名的 RSS 源下载图像。

示例 -

我要下载的图片网址(如果你在浏览器中点击它可以工作,但在代码中它不起作用):

http://www.deviantart.com/download/286471805/

使用下面的代码,我得到“WebClient 请求期间发生异常”。错误。我不知道为什么这不起作用。

关于如何保存这些文件有什么想法吗?

    private void Start_Button_Click(object sender, EventArgs e)
    {
        WebClient MyDownloader = new WebClient();

            MyDownloader.DownloadFile(@"http://www.deviantart.com/download/286471805/", @"c:\test\");

    }

【问题讨论】:

    标签: c# image downloadfile


    【解决方案1】:

    您必须指定文件名作为第二个参数,而不是下载目录:

    using (var client = new WebClient())
    {
        client.DownloadFile("http://www.deviantart.com/download/174633066/",
                            @"c:\test\file.png");
    }                                     ↑
    

    【讨论】:

    猜你喜欢
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-22
    相关资源
    最近更新 更多