开发者

WebClient DownloadFileAsync Illegal characters in path

开发者 https://www.devze.com 2023-04-09 03:19 出处:网络
I am using WebClient.DownloadFileAsync to download files asynchronously to my machine. Occasionally, I end up with URLs which has a double quote on it.

I am using WebClient.DownloadFileAsync to download files asynchronously to my machine. Occasionally, I end up with URLs which has a double quote on it.

For example, see this:

http://upload.wikimedia.org/wikipedia/en/d/d3/"Baby"_Palace_Hotel_1906.jpg.

DownloadFileAsync throws an "Illegal characters in path" exception when the file name contains double quotes. I am unable to decode the url either since DownloadFileAsync does not accept string as a parameter but only Uri.

What would be a good way to handle this sit开发者_开发百科uation?


Weird, the follownig works fine for me:

class Program
{
    static void Main()
    {
        using (var client = new WebClient())
        {
            client.DownloadFileCompleted += (sender, e) =>
            {
                Console.WriteLine("finished");
            };
            client.DownloadFileAsync(new Uri("http://upload.wikimedia.org/wikipedia/en/d/d3/\"Baby\"_Palace_Hotel_1906.jpg"), "test.jpg");
            Console.ReadLine();
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消