Solved

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

Posted on 2010-09-22
6
447 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 to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

19 Experts available now in Live!

Get 1:1 Help Now