Solved

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

Posted on 2004-08-24
7
1,591 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
RLDC Reporting in Visual studio 11 44
VB.Net. Reading xml value 6 38
Name Space error VS2015 1 37
Must we use a disconnected model when creating database applications? 6 26
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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 …
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…

733 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