I'm currently using the DuckDuckGo icon utility to fetch the favicon's for certain webpages, although in order to fetch an icon it requires you to add ".ico" at the very end of the request, for example: https://icons.duckduckgo.com/ip2/www.google.com.ico
So, I'm using a WebClient
to download the favicon, although; it doesn't seem to be downloading it completely since every time I open the file it appears corrupted and throws an error stating that "the file header can't be read".
I've tried the following so far (my WebClient
is called client
, the icon to set is called favicon
and the path to the icon file is called favicon_path
):
Uri favicon_url = new Uri(
"https://icons.duckduckgo.com/ip2/" + gBrowser.Url.Host.ToString() + ".ico");
client.DownloadFile(@favicon_url, favicon_path);
favicon = new Icon(favicon_path);
and
Uri favicon_url = new Uri("https://icons.duckduckgo.com/ip2/"
+ gBrowser.Url.Host.ToString().Replace(".", "%2E") + ".ico");
client.DownloadFile(@favicon_url, favicon_path);
favicon = new Icon(favicon_path);
I'm guessing that the multiple periods ('.'
) in the favicon_url are responsible, so my question is: How can I download the favicon using a WebClient
(or something similar) if it has multiple periods in its name? Or if not the periods, why can't I read the file downloaded from DuckDuckGo?