?
Solved

Retriving Favicon.ico from an URL

Posted on 2004-09-22
2
Medium Priority
?
831 Views
Last Modified: 2010-04-16
Hi,

How can I retrive a Favicon.ico from an URL and store it locally? I want to do it on the fly and the URL will not be in my IE Favorites, but it would certainly be among the visited sites.

Let me explain it further, I have a TWebBrowser component and a button-click will fetch the favicon.ico from the URL (currently browsed by TWebBrowser). So, there may be a possibility to grab the .ico from IE history folder (just a hint, I am very much open to other solutions also).

So, ideally I will pass the URL to a function and it will store the icon locally.

regards,
Partha



0
Comment
Question by:perthg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
Ferruccio Accalai earned 2000 total points
ID: 12131214
you could use the EddieShipman example from here http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20986816.html#11053973

or maybe this method (just an idea) using urlmon: it get the favicon.icon from the homepage of whatever page you're browsing:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw,urlmon, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
    Button2: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    Function GetFavIcon( Url: string;dest: String): Boolean ;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

Function TForm1.GetFavIcon( Url: string;dest: String): Boolean;
var i: Integer;
begin
If Pos('HTTP://',UPPERCASE(URL)) > 0 then
   delete(Url,1,7);
i := pos('/',url);
If i > 0 then
   Url := 'http://'+copy(url,1,i);

   Result := UrlDOwnloadToFile(nil,PCHar(Url+'favicon.ico'),Pchar(dest),0,nil) = 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21141761.html');
end;

procedure TForm1.Button2Click(Sender: TObject);
var
Url :STring;
begin
If GetFavIcon(WebBrowser1.LocationUrl,'c:\favicon.ico') then
   Image1.Picture.LoadFromFile('c:\favicon.ico')
else
   Image1.Picture := nil;
end;

end.

F68;
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 12135382
Whoa, Ferruccio68, thanks for the link...
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question