Get Favicon from a website for webbrowser control

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
6 posts Page 1 of 1
Contributors
User avatar
Danny
VIP - Donator
VIP - Donator
Posts: 621
Joined: Sat Oct 30, 2010 8:21 pm

hello guy's I have a little tutorial for you!
mmm well I put it in this zip and it is free ofcourse

first open vb or visual studio ->
add a picturebox and a webbrowser
set http://www.codenstuff.com as default webbrowser url
Code: Select all
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate("www.codenstuff.com")
    End Sub
then ad these codes:
Code: Select all
Private Sub WebBrowser1_Navigated(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
        Dim response As System.Net.HttpWebResponse
        Dim request As System.Net.WebRequest
        Dim iconURL As String
        Dim favicon As Image
        Dim stream As System.IO.Stream
        Dim url As Uri = WebBrowser1.Url
        If url.HostNameType = UriHostNameType.Dns Then
            iconURL = "http://" & url.Host & "/favicon.ico"
            request = System.Net.HttpWebRequest.Create(iconURL)
            Try
                response = request.GetResponse()
                stream = response.GetResponseStream()
            Catch
                For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("link")
                    If element.GetAttribute("rel").ToUpper = "SHORTCUT ICON" Then
                        Dim iconplace As String = element.GetAttribute("href")

                        request = System.Net.HttpWebRequest.Create(WebBrowser1.Url.ToString + iconplace)
                        response = request.GetResponse()
                        stream = response.GetResponseStream()
                        favicon = Image.FromStream(stream)
                        Me.PictureBox1.Image = favicon
                        Exit For
                    End If
                Next
            End Try
            If Not stream Is Nothing Then
                favicon = Image.FromStream(stream)
                Me.PictureBox1.Image = favicon
            End If
        End If
end sub
that are the codes.
set the picturebox size to 24 x 24 to get the perfect size!
and now test it!
+rep if you liked this!
webbrowser website favicons.rar
You do not have the required permissions to view the files attached to this post.
User avatar
XTechVB
VIP - Site Partner
VIP - Site Partner
Posts: 727
Joined: Thu May 20, 2010 10:32 am

Good Tutorial! but i think this was posted before, still good job
You can find me on Facebook or on Skype mihai_92b
User avatar
Danny
VIP - Donator
VIP - Donator
Posts: 621
Joined: Sat Oct 30, 2010 8:21 pm

XTechVB wrote:
Good Tutorial! but i think this was posted before, still good job
ow I am sorry I didn't noticed that blusho;
User avatar
Agust1337
Coding God
Coding God
Posts: 2456
Joined: Fri Feb 19, 2010 8:18 pm

Yeah, I posted one but it's alright, I think people forgot about it anyway... lol
Keep it up cooll;
Top-notch casual Dating
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

It was also posted in the tutorial "CNS Browser" which is located in the Tuts and Downloads section.
Image
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Just find "Tabbed Web Browser" on codenstuff and it has the exact same code :) But nice sharing xD
6 posts Page 1 of 1
Return to “Tutorials”