[2005] Favicon.ico in VB.NET?
Hi. I was wondering how you access the favicon.ico of a website that you are currently on in a webbrowser control and place it at the front of a textbox. I have heard that you can use javascript for this. If this is so, then what javascript would I use and is there a link to how to incorporate javascript in vb.net? Thanks :)
Re: [2005] Favicon.ico in VB.NET?
If you look in the source, a website with a favicon file will have one or more of the following tags in the <head> section:
<link rel="icon" href="http://example.com/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="http://example.com/favicon.ico" type="image/x-icon" />
More info about it can be found on the wikipedia page.
You can parse the source of the document checking to see if there is a <link> tag and if the "rel" property contains "icon" or "shortcut icon". It might be possible to use the XML class to do this, I've never actually tried it myself, but XML is just customizable HTML anyway.
Once you parse out the path to the image, you can use the System.Net.WebClient class to download the image to a temporary path and then set the Textbox's image or background image property (does it have one?) to the file using Bitmap.FromFile() and the ImageAlign property to MiddleLeft (again, does it have that?). If there aren't those properties, you can still do it using the paint event or creating your own drawing surface.
Re: [2005] Favicon.ico in VB.NET?
Well I got the webclient to work, I don't know how to parse the webbrowser's document....any links? (in the meantime I will be searching). I downloaded the file but I cannot set the textbox's property to show the image. How could I use the paint event/creating my own drawing surface?
Re: [2005] Favicon.ico in VB.NET?
You basically need to just go through the WebBrowser.DocumentText looking for a <link tag, and if has rel="icon" or rel="shortcut icon" before the next > (the closing tag) then it is a favicon link, and you can search for the href=" part of the tag and download the image using the webclient.
And I'm not really a heavy GDI user, so I'm not entirely sure how you can draw the image onto the textbox. I see now that it doesn't have any image properties like a label does, so you will have to do that. Try searching the forums for GDI programming, I'm sure they're something you can use for that portion. But first you need to get the image downloaded. :) You might also want to just use an ImageCombo if you are using this for a browser address bar. Then it would be easy to add the image to the current item.
Re: [2005] Favicon.ico in VB.NET?
Could you explain what you meant by ImageCombo?
Quote:
You might also want to just use an ImageCombo if you are using this for a browser address bar. Then it would be easy to add the image to the current item.
Re: [2005] Favicon.ico in VB.NET?
http://www.vbforums.com/showthread.p...ght=imagecombo
It was a control from VB6, I guess it didn't get included with the .NET stuff, but according to this post, you can get a customized one that inherits all the properties of the original ComboBox but includes support for images.