Mega Code Archive

 
Categories / Delphi / Files
 

Downloading a file from a URL

Title: Downloading a file from a URL Question: How do I download a file from a www address? Answer: Windows has the function you need already declared in the UrlMon.dll. Declare UrlMon in the uses clause ............ function DownloadFile(Source, Dest: string): Boolean; begin try Result := UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0; except Result := False; end; end; //Example: procedure TForm1.Button1Click(Sender: TObject); begin if DownloadFile ('http://www.delphi3000.com/index.htm, 'c:\index.htm') then ShowMessage('Download successful') else ShowMessage('Download unsuccessful') end;