locked
Local Html file in browser. RRS feed

  • Question

  • I'm a teenager and currently working on a VB 2010 project. So far it is looking really good. I just need to know how to load a local html file into the web browser. I remember the code to make a web browser:

    WebBrowser1.Navigate = Textbox1.text

    I have the .html file in the root of the project. I tried:

    WebBrowser1.Navigate = ("file.html")

    It doesn't work.

    Thursday, February 6, 2014 2:49 AM

Answers

  • I'm a teenager and currently working on a VB 2010 project. So far it is looking really good. I just need to know how to load a local html file into the web browser. I remember the code to make a web browser:

    WebBrowser1.Navigate = Textbox1.text

    I have the .html file in the root of the project. I tried:

    WebBrowser1.Navigate = ("file.html")

    It doesn't work.


    Option Strict On
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim OFD As New OpenFileDialog
            OFD.Title = "Open file for WebBrowser"
            OFD.InitialDirectory = "C:\Users\John\Desktop"
            OFD.Multiselect = False
            If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
                WebBrowser1.Navigate(OFD.FileName)
            End If
        End Sub
    
    End Class


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


    • Edited by Mr. Monkeyboy Thursday, February 6, 2014 4:25 AM 5555
    • Proposed as answer by IronRazerz Thursday, February 6, 2014 4:32 AM
    • Marked as answer by Leo (Apple) Yang Wednesday, February 12, 2014 5:58 AM
    Thursday, February 6, 2014 4:24 AM

All replies

  • Hi,

     You can try it like this.

    WebBrowser1.DocumentText = System.IO.File.ReadAllText("C:\TestFolder\ffmpeg.html")

    Thursday, February 6, 2014 3:46 AM
  • It should work.  Check that the string doesn't have extraneous spaces or invisible characters.  Double click on the file in explorer.
    Thursday, February 6, 2014 4:07 AM
  • I'm a teenager and currently working on a VB 2010 project. So far it is looking really good. I just need to know how to load a local html file into the web browser. I remember the code to make a web browser:

    WebBrowser1.Navigate = Textbox1.text

    I have the .html file in the root of the project. I tried:

    WebBrowser1.Navigate = ("file.html")

    It doesn't work.


    Option Strict On
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim OFD As New OpenFileDialog
            OFD.Title = "Open file for WebBrowser"
            OFD.InitialDirectory = "C:\Users\John\Desktop"
            OFD.Multiselect = False
            If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
                WebBrowser1.Navigate(OFD.FileName)
            End If
        End Sub
    
    End Class


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


    • Edited by Mr. Monkeyboy Thursday, February 6, 2014 4:25 AM 5555
    • Proposed as answer by IronRazerz Thursday, February 6, 2014 4:32 AM
    • Marked as answer by Leo (Apple) Yang Wednesday, February 12, 2014 5:58 AM
    Thursday, February 6, 2014 4:24 AM
  • After testing my example and trying to click on one of the link labels in the document it failed to work correct so i would go with using the Navigate method as Mr. Monkeyboy has shown and use the full pathname to the html file.
    Thursday, February 6, 2014 4:37 AM
  • The file name alone is not valid syntax for a local HTML file URL. For a local HTML file you need to specify the full path

    WebBrowser1.Navigate("file://<path to file>\file.html")


    Paul ~~~~ Microsoft MVP (Visual Basic)



    Thursday, February 6, 2014 3:04 PM
  • I can't get "WebBrowser1.Navigate =" to work. It errors with an overload resolution error in the second pic in the first image below. The code in the top pic in the first image works fine for an .Htm file on my desktop.


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


    • Edited by Mr. Monkeyboy Thursday, February 6, 2014 4:29 PM 5555
    Thursday, February 6, 2014 4:28 PM
  • The file name alone is not valid syntax for a local HTML file URL. For a local HTML file you need to specify the full path

    WebBrowser1.Navigate = ("file://<path to file>\file.html")


    Paul ~~~~ Microsoft MVP (Visual Basic)



     You may want to remove the "=" sign. Navigate does not use an "=".   :)
    Thursday, February 6, 2014 5:50 PM
  •  You may want to remove the "=" sign. Navigate does not use an "=".   :)

    Yeah, fixed it. That's what you get for copying someone else's code. Thanks!


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, February 6, 2014 10:17 PM