Wednesday, December 10, 2008

Download file from URL

static void JobDownloadFromURL(Args _args)
{
Url url;
int iHandle;
WinInet winInet;
Filename filename;
TextBuffer textBuffer;
;

winInet = new WinInet();
textBuffer = new TextBuffer();
filename = "c:\\temp\\valuta_dag.sdv";
url =
"http://www.norges-bank.no/webdav/stat/no/valutakurser/valuta_dag.sdv";

iHandle = winInet.internetOpenUrl(url);
if (iHandle == 0)
{
error(strfmt("Error open: %1", url));
return;
}

textBuffer.appendText(winInet.internetReadFile(iHandle));

winInet.internetCloseHandle(iHandle);

textBuffer.toFile(filename);

info(strfmt("Lines: %1", textBuffer.numLines()));

}

No comments: