Solved

How do you do a FILE > SAVE AS with IE from VB.NET

Posted on 2004-08-24
7
1,606 Views
Last Modified: 2008-01-09

I have code doing the following...

    Private WithEvents IE As SHDocVw.InternetExplorer

        If TextBox1.Text <> "" Then
            If IE Is Nothing Then
                IE = New SHDocVw.InternetExplorer
            End If

            IE.Visible = True
            IE.Navigate(TextBox1.Text)

            Do While IE.Busy
                Application.DoEvents()
            Loop

            ' page finished loading...
            ' do something in here

        End If

I have other code doing something with IE after the page is loaded.  It all works fine.

But I want to programatically perform the FILE > SAVE AS functionality as if you did it with the mouse interactively.  

How can I do a FILE > SAVE AS (including specifying a SAVE AS file type) with an IE object as I have it in the code above ?

Thanks,

John

0
Comment
Question by:trzesniakj
[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
  • 2
7 Comments
 
LVL 4

Expert Comment

by:Daniellus83
ID: 11887801
Okay; there are two things:

> 1. opening/setting the filename of the file you wanna do the save-ass operation to
> 2. get the information from the loaded html document and save it 'as' file...

(use also this link:  http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20953741.html )

ad 1.:

        Dim number As Integer = FreeFile()
        Dim FileName As String

        If SaveFile.ShowDialog() = DialogResult.OK Then

            FileName = SaveFile.FileName & ".html"
            FileOpen(nummer, FileName, OpenMode.Output) ' Open file for output.
           
            WriteLine(number , "your text")

            FileClose(nummer)
        End If


ad 2.: use this VB-code:

   Private Sub Form_Load()
      WebBrowser1.Navigate "www.google.com"
   End Sub
   
   Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
      Dim sHead As String, sBody As String
      sHead = WebBrowser1.Document.All.tags("HEAD").Item(0).outerhtml
      sBody = WebBrowser1.Document.body.outerhtml
      Debug.Print "<HTML>" & sHead & sBody & "</HTML>"
   End Sub


Now, this combined with your code should be:

------------------------------------------------------------------------------------------------------
    Private WithEvents IE As SHDocVw.InternetExplorer

        If TextBox1.Text <> "" Then
            If IE Is Nothing Then
                IE = New SHDocVw.InternetExplorer
            End If

            IE.Visible = True
            IE.Navigate(TextBox1.Text)

            Do While IE.Busy
                Application.DoEvents()
            Loop
 
         '--------------------------------------------------------------
            Dim number As Integer = FreeFile()
            Dim FileName As String
            Dim sHead As String, sBody As String


            If SaveFile.ShowDialog() = DialogResult.OK Then

                FileName = SaveFile.FileName & ".html"
                FileOpen(nummer, FileName, OpenMode.Output) ' Open file for output.
           
                     sHead = IE.Document.All.tags("HEAD").Item(0).outerhtml
                     sBody =  IE.Document.body.outerhtml

                 WriteLine(number , "<HTML>" & sHead & sBody & "</HTML>")
 
                 FileClose(nummer)
             End If

        End If
------------------------------------------------------------------------------------------------------

Warning: you have to add a 'SaveFileDialog' to your Form (and call it "SaveFile") to get this working.
0
 
LVL 4

Expert Comment

by:Daniellus83
ID: 11887848
sorry; forgot to replace some of varnames. Here is the corrected code:

------------------------------------------------------------------------------------------------------
    Private WithEvents IE As SHDocVw.InternetExplorer

        If TextBox1.Text <> "" Then
            If IE Is Nothing Then
                IE = New SHDocVw.InternetExplorer
            End If

            IE.Visible = True
            IE.Navigate(TextBox1.Text)

            Do While IE.Busy
                Application.DoEvents()
            Loop
 
         '--------------------------------------------------------------
            Dim number As Integer = FreeFile()
            Dim FileName As String
            Dim sHead As String, sBody As String


            If SaveFile.ShowDialog() = DialogResult.OK Then

                FileName = SaveFile.FileName & ".html"
                FileOpen(number, FileName, OpenMode.Output) ' Open file for output.
           
                     sHead = IE.Document.All.tags("HEAD").Item(0).outerhtml    '<< This code might be different
                     sBody =  IE.Document.body.outerhtml                                '<< This code might be different

                 WriteLine(number , "<HTML>" & sHead & sBody & "</HTML>")
 
                 FileClose(number)
             End If

        End If
------------------------------------------------------------------------------------------------------
0
 

Author Comment

by:trzesniakj
ID: 11888234
No.  You're not quite understanding what I want to do.  My original request had it correct.

To clarify...I do not want my VB.APP to do the saving (although your code is perfectly fine to do that).  I want to use IE's save as capabilities.

So I'll ask again...I want to programatically perform the FILE > SAVE AS functionality as if you did it with the mouse interactively.  How can I do a FILE > SAVE AS (including specifying a SAVE AS file type) with an IE object as I have it in the code above ?

Thanks,

John
0
 
LVL 4

Accepted Solution

by:
Daniellus83 earned 500 total points
ID: 11890125
Okay; the answer to that is:

 you cannot do this only with this component!  (check this: http://www.experts-exchange.com/Community_Support/help.jsp#hi54)

Daniël
0
 

Author Comment

by:trzesniakj
ID: 11891693
Thank you for taking the time to reply.  I appreciate the effort.

I'd like to know if anyone else has a potential solution to this.

Thanks,

John
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

690 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