Click here to Skip to main content
15,918,109 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I need to download a list of PDF files from an Australian Government website, and i dont want to download them manually, so i need a program to download them.

The website we are requiring documents from is:[^]

Below is my current code:

Public Class Form1
    Public agreementPassed As Boolean = False
    Public hyperLinkList As List(Of String) = New List(Of String)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        agreementPassed = True
For Each singleLink As String In hyperLinkList
        WebBrowser1.Name = "pdf"
        WebBrowser1.Navigate(New Uri(singleLink))
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    WebBrowser1.Navigate(New Uri(hyperLinkList(0)))
End Sub

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        If agreementPassed Then
            IO.File.WriteAllText("C:\temp.pdf", New IO.StreamReader(WebBrowser1.DocumentStream).ReadToEnd)
        End If
    End Sub
End Class

I populate the LinkedList by another button i havn't included, but that works. Button 2 is used to just display the first page to agree to the conditions and generate the cookie. When i click Button1 its meant to save each link. All that happens though is the last URL opens the PDF in Adobe outside of the program and the HTML page that is seen when you need to click "I Agree" is saved to Temp.pdf.

I'm open to any ideas on how to do this, and if i need to get rid of the WebBrowser, i'm happy to do that too.

1 solution

You could use WebRequest class first to get document with links to pdf files than pares it and get each pdf file using WebRequest.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900