Question : Saving the html file from the web browser control in VB.NET


I'm trying to save the HTML document that is displayed in the web browser control in my VB.NET app. It looks like I can save it via AxWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_SAVE, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT) but I can't figure out what file name it saved it as. I don't want to prompt the user for a filename, I need to determine that at runtime.

Answer : Saving the html file from the web browser control in VB.NET

Hi bfeddish,

I use something like this code......

Imports InetCtlsObjects                '<----AxInterop.InetCtlsObjects.dll

dim sDefaultPage as string ="MYURL"         '<---- like... http://www.Bahbahbhab.com
dim sWebCode  as string

            'This will display the first screen of data
            AxWebBrowser1.Navigate2(sDefaultPage)
         
          'Copy source code from web site of finished screen
            sWebCode = AxInet.OpenURL(sDisplayPage)

StreamWriterCREATEFile( "MYFileName", sWebCode)

'Then just save to a text file using writerstream.

   Public Sub StreamWriterCREATEFile(ByVal sFileName As String, ByVal sData As String)
        Dim myStreamWriter As StreamWriter
        Dim Temp As String
        Dim i As Short

        Try
            myStreamWriter = File.CreateText(sFileName)
            myStreamWriter.Write(sData)
             myStreamWriter.Flush()
        Catch exc As Exception
            MsgBox("File could not be created or written to." + vbCrLf + _
                "Please verify that the filename is correct, " + _
                "and that you have write permissions for the desired " + _
                "directory." + vbCrLf + vbCrLf + "Exception: " + exc.Message)
        Finally
            ' Close the object if it has been created.
            If Not myStreamWriter Is Nothing Then
                myStreamWriter.Close()
            End If
        End Try
    End Sub

Random Solutions  
 
programming4us programming4us