Help with a web browser open file dialog please.

Help with a web browser open file dialog please

Page 1 of 1

2 Replies - 10897 Views - Last Post: 31 October 2008 - 10:00 AM Rate Topic: -----

#1 Lumnous  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-October 08

Help with a web browser open file dialog please.

Post icon  Posted 28 October 2008 - 11:56 AM

Help I Need to find out how to open files in a web browser, i get it open the dialog and navigating but it does not then open the image or documents at all. Can someone help please ? Thankyou.

 Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
		WebBrowser1.Navigate(OpenFileDialog1.ShowDialog)
	End Sub

What i have put here is that when the button is clicked Open file dialog will open up,then i shall select my file and it should appear in the web browser. But this code does not work right, the only problem I can find is WebBrowser1 does not want to load the image.

Is This A Good Question/Topic? 0
  • +

Replies To: Help with a web browser open file dialog please.

#2 rakyomin  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 77
  • Joined: 12-September 08

Re: Help with a web browser open file dialog please.

Posted 30 October 2008 - 03:54 PM

I was surprised no one answered this thread...

Actually there is a great tutorial here you can find it is written by gbertolis3, inside mentioned openfiledialog which is exactly what you need here.

your above code will not work..
try this.
I am not sure how you implement user to click open file, my method is use a menustrip add an openfile tool strip, and add the code into the click event. If you have add reference system.windows.forms and system.io.file then you do not need to write Windows.Forms.DialogResult.OK and System.IO.File.ReadAllText(path as string), you only need to write dialogresult.ok and readalltext(path as string)
You can modify the filter, this filter is for convenience...
Whenever a user open a file, a text file or html file, the contents will be read by system.io.file and directs to webbrowser.documenttext.

Private Sub OpenFileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenFileToolStripMenuItem.Click
        Dim OFD As New OpenFileDialog()
        With OFD
            .Filter = "All Files |*.*"
            .FileName = ""
        End With
        If (OFD.ShowDialog() = Windows.Forms.DialogResult.OK) Then
            WebBrowser1.DocumentText = _
           System.IO.File.ReadAllText(OFD.FileName)

        End If

    End Sub


Was This Post Helpful? 1
  • +
  • -

#3 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Re: Help with a web browser open file dialog please.

Posted 31 October 2008 - 10:00 AM

Quote

Actually there is a great tutorial here you can find it is written by gbertolis3, inside mentioned openfiledialog which is exactly what you need here.

Well Thank You!

I have created a lot of WebBrowser Tutorials for C#, but now I'm trying to have them be in VB.NET as well.

This post has been edited by gbertoli3: 31 October 2008 - 10:00 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1