Solved

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

Posted on 2010-09-22
6
463 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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