DelphiFAQ Home Search:

Download a file from the web (internet)

 

comments2 comments. Current rating: 5 stars (2 votes). Leave comments and/ or rate it.

Question:

Is there an easy function to download a file via http protocol?

Answer:

Yes, there is. It's called UrlDownloadToFile() and it's defined in unit URLMon. The code below shows how to use it.

uses 
  URLMon; 

//-------------------------------------------------------------
// SourceFile = http address e.g. http://www.ibm.com/test.gif
// DestFile = filename where to save the file
//
function DownloadFile(SourceFile, DestFile: string): Boolean; 
begin 
  try 
    Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0; 
  except 
    Result := False; 
  end; 
end; 
You don't like the formatting? Check out SourceCoder then!
Content-type: text/html

Comments:

2006-01-25, 03:22:04
[hidden] from United Kingdom  
rating
thanks a lot
I think it is the easiest way
Piotr Borowski
2006-07-20, 09:23:28
anonymous from United States  
rating
Thanks - It rare to be able to find a cut and paste solution!

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: