How can I get a web site's favicon?

前端 未结 14 2171
旧巷少年郎
旧巷少年郎 2020-12-22 15:28

Simple enough question: I\'ve created a small app that is basically just a favourites that sits in my system tray so that I can open often-used sites/folders/files from the

14条回答
  •  孤城傲影
    2020-12-22 15:44

    HttpWebRequest w = (HttpWebRequest)HttpWebRequest.Create("http://stackoverflow.com/favicon.ico");
    
    w.AllowAutoRedirect = true;
    
    HttpWebResponse r = (HttpWebResponse)w.GetResponse();
    
    System.Drawing.Image ico;
    using (Stream s = r.GetResponseStream())
    {
        ico = System.Drawing.Image.FromStream(s);
    }
    
    ico.Save("favicon.ico");
    

提交回复
热议问题