Solved

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

Posted on 2010-09-22
6
465 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
Technology Partners: 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Import a excel sheet in a grid 2 45
Help with viewing image in ReportViewer 14 32
Select coumns form Data table? 3 27
How does this modal gets closed? 6 42
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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