?
Solved

Retriving Favicon.ico from an URL

Posted on 2004-09-22
2
Medium Priority
?
842 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
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:Eddie Shipman
ID: 12135382
Whoa, Ferruccio68, thanks for the link...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

839 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