1

Possible Duplicate:
How can I get a web site’s favicon?

I use these following codes to get the site favicon in a c# windows application to show that in a picture box.

HttpWebRequest web = (HttpWebRequest)HttpWebRequest.Create(downloadstring);
web.AllowAutoRedirect = true;
try
{
    HttpWebResponse res = (HttpWebResponse)web.GetResponse();
    System.Drawing.Image ico;
    using (Stream s = res.GetResponseStream())
    {
        ico = System.Drawing.Image.FromStream(s);
    }
    pictureBox1.Image = ico;
}
catch (Exception)
{

}

The problem is it's gonna just show the favicon if it has been located in the main root server (for example www.example.com/favicon.ico) but if the icon is in another folder it won't work.

How can I get the favicon if it is in any folder of the root server?

Community
  • 1
  • 1
  • 1
    A browser has two options to locate that favicon: 1) in the root of the site; 2) according to the specification in the html file (some meta tag). You will need to do the same, there is no way to get at a file in "any folder". – Hans Kesting Nov 10 '12 at 14:58
  • @HansKesting in some wordpress site it has been located in theme folder –  Nov 10 '12 at 15:00
  • @peterpurcell - still, the browser doesn't know about that "wordpress" location, unless told through that meta tag. If *you* are sure it's a wordpress site, then try that theme folder. – Hans Kesting Nov 10 '12 at 15:03

0 Answers0