Solved

how do i save down a PDF file from an open Internet Explorer window

Posted on 2010-09-22
6
451 Views
Last Modified: 2012-05-10
Hi. I need to find a way of downloading a PDF file from an OPEN internet explorer window and then SAVE AS like i have tried in my sample code.
That code seem to work for HTML pages but not PDFs.
The idea is to download new documents from an open webpage, where a login password is needed.


Since there is a password necessary on the website, using System.Net.WebClient seem not to be an option ( i couldn't get it to login correctly)

Dim objStream1 As New System.Net.WebClient
        objStream1.DownloadFile("")

I have also tried varios SEND KEYS to the window, but its not working and usually doesn't give that much stability
Sub saveas(ByVal url As String)
        Dim filename2 As String
        Dim doc As mshtml.HTMLDocument
        For Each window In shellWindows
            Dim HTMLdocument2 As Object
            IEInstance = window '...see if they are IE windows...
            filename2 = Path.GetFileNameWithoutExtension(IEInstance.FullName).ToLower()
            If filename2.Equals("iexplore") Then

                Try
                    Timer1.Enabled = False
                    filename2 = IEInstance.LocationURL
                    If filename2.ToString = url.ToString Then
                       
                        Do
                        Loop Until Not IEInstance.Busy
                        IEInstance.ExecWB(SHDocVw.OLECMDID.OLECMDID_SAVECOPYAS, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, "C:\testing.pdf", Nothing)

                      
                    End If

                  

                Catch

                End Try
            End If
        Next

    End Sub

Open in new window

0
Comment
Question by:soriega
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:leechoonhwee
ID: 33737802
You mentioned that there is a password to be entered but what happen after the password is being entered? Does the URL being redirected points directly to a http download?
0
 

Author Comment

by:soriega
ID: 33738684
Well if i try to open the URL by entering it in the adressbar, i get to a "logon" page of the website. After entering the credentials there i get to the webpage.pdf which opens in explorer. However, i can't get this to work from within vb.net app. Therefore i have tried using the above code which tries to "save as" from an external window (internet explorer window)
0
 
LVL 9

Expert Comment

by:leechoonhwee
ID: 33741849
If you can accept the web browser inside your winform then you can use wb.navigate("http:....................") and then it should prompt to save the file from within the winform.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 9

Expert Comment

by:leechoonhwee
ID: 33741915
Or you could do this.




Imports System.Net


Public Class Form1
    Dim LoginType As String

    Private Sub wb_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles wb.DocumentCompleted
        Select Case LoginType
            Case "FirstLogin"
                wb.Document.GetElementById("password").DomElement.value = "xxxx" 'Replace pass with the name of the password field of the form
                wb.Document.GetElementById("login_form").DomElement.submit() ' Replace the login_form with the name of the submit button of the form
                LoginType = "DownloadFile"

            Case "DownloadFile"
                Dim wc As New WebClient
                wc.DownloadFile(wb.Document.Url, yourfilename)

        End Select

    

      
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        wb.Navigate("Http:.............")
        LoginType = "FirstLogin"
    End Sub
End Class

Open in new window

0
 

Accepted Solution

by:
soriega earned 0 total points
ID: 34015379
Thanks for the answers to many other things than the problem i have with the PDF in a webbrowser, the answers above where the first things i  tested, and they don't work. The elementID for password etc can't be found either.

Still as i pointed out in my question, i Cannot USE the browser inside the vb app itself. For some reason i get problems with both the PDF addon aswell as some javascripts etc on the website.
I now have a decent "sendkeys" solution to an external webapp, this works even though a "non mouseevent" solution would be preferable.
So if anyone knows anything about how to use the DLL for foxitreader please help out with that. Or maybee adobe reader even though that reader is very slow compared to foxit i think....
0
 

Author Closing Comment

by:soriega
ID: 36388125
problem not solved
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now