Solved

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

Posted on 2010-09-22
6
474 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

632 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