开发者

WebClient DownloadFileAsync Illegal characters in path

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜