Results 1 to 5 of 5

Thread: WebBrowser control is not displaying local HTML files

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2013
    Posts
    91

    Question WebBrowser control is not displaying local HTML files

    Hi guys

    I wasted a week so far reading and trying all the solutions I can find on the net only to find that they do no work.

    I have a listbox that shows the filename of all files in a "show" folder. Clicking on a filename should display the HTML file in the webbrowser control.

    Here is the code I'm using at the moment and the actual file location is "D:\The Penfound Project\family\show\1.html"

    Code:
       Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
            Dim SF, URLString As String
            SF = ListBox1.SelectedItem.ToString
            SF = myPath & SF
            WebBrowser1.AllowNavigation = True
            URLString = "file:///" & SF
            URLString = URLString.Replace("\", "/") 'this does not work
            'URLString = "https://penfound.org" 'this works
            Me.WebBrowser1.Navigate(URLString)
            WebBrowser1.Update()
        End Sub
    When I click on a filename the program locks up wit ha blank browser area.
    Last edited by dday9; Mar 5th, 2018 at 04:18 PM.

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,543

    Re: WebBrowser control is not displaying local HTML files

    It's been a while, but I believe it should be file:// not file:///

    And those should be the only forward slashes, the rest in the path should remain as back slashes.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,191

    Re: WebBrowser control is not displaying local HTML files

    Quote Originally Posted by techgnome View Post
    It's been a while, but I believe it should be file:// not file:///

    And those should be the only forward slashes, the rest in the path should remain as back slashes.

    -tg
    At least using Chrome, opening a local HTML results in file:///C:/Users/FMS-VB/Documents/test.html in its address bar.

    Quote Originally Posted by Penfound View Post
    URLString = URLString.Replace("\", "/") 'this does not work
    What is the value of URLString after this line?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2013
    Posts
    91

    Re: WebBrowser control is not displaying local HTML files

    Thanks for your input guys - unfortunately neither works.
    Maybe MS will make one that does work in the next edition of VS

  5. #5
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,191

    Re: WebBrowser control is not displaying local HTML files

    Quote Originally Posted by Penfound View Post
    Thanks for your input guys - unfortunately neither works.
    Maybe MS will make one that does work in the next edition of VS
    Define doesn't work. What error are you getting? Perhaps you should trap whatever exception you must be getting to lock up.

    Using VS2013 on WIn 7, I can do
    Code:
            Try
                Me.WebBrowser1.Navigate("file:///C:/Users/FMS-VB/Documents/test.html")
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try
    and it shows my test page. I'm thinking your URLString isn't exactly what you think it is or there is some kind of permissions issue or maybe something wrong with the HTML in the file.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width