Automatically download and save pdf files from a website.

M

MJ

Automatically download and save pdf files from a website.

Is there a way to do this?

I would like to automate a daily procedure for downloading and saving a
couple of dozen pdf from several websites. Currently I have saved bookmarks
in a browser and manually open and save each one.

Some of the files have direct addresses, for example:
https://www.somewebsite.com/resources/documents/daily_price_sheet.pdf

Some are dynamically generated, for example:
https://www.somewebsite.com/resourc...e_sheets.jsp&account=012345&state=MA&type=wsl
(this returns a pdf file to the browser)


I can get the directly addressed documents with some simple scripting of an
FTP client. It's the dynamically generated files that I'm having a hard time
figuring out. The only way I've been able to get the dymamically generated
files seems to be to request the url through a browser.


(Windows XP pro, ie 6.0, Acrobat Reader 7.0.0, VB.NET 2003)


Dim ieApp As SHDocVw.InternetExplorer = New SHDocVw.InternetExplorer
Dim sURL as String = "URL of file I want"
ieApp.Navigate(sURL)

This seems to work fine. Launches a browser, navigates to the URL, browser
invokes Acrobat, pdf document is displayed.

The two problems I don't know how to solve are:

1) Determining when the pdf document has finished downloading.
2) Saving it.


Thanks.

Mike
 
J

Jason Newell

Mike,

Here is some of my C# code that I use. Should be very easy to translate
into VB.NET. Give it a try and let me know how it goes.

WebClient webClient = new WebClient();
try
{
webClient.Credentials = CredentialCache.DefaultCredentials;
webClient.DownloadFile(url, fileName);
}
catch (System.Exception e)
{
// Do something with exception
}
finally
{
webClient.Dispose();
}


Jason Newell
 
M

MJ

Thanks a million Jason & Herfried. That's exactly what I was looking for. I
had no idea it was there (is my newbieness showing?).

Thanks again,
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top