How to know the filename when the user clicked?

Hi all professionals,

When i make the component of webbrowser as a windows explorer, i knew how to get a path of the user's click. But how to get the filename what is the user double click to open?

Thanks!

[216 byte] By [BennyLam] at [2008-1-9]
# 1
Hi,

How to know the filename when the user clicked in web browser component?

Thanks!

BennyLam at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

Benny Lam,

Based on your post, you are using WebBrowser control as Windows Explorer and retrieve the open file name when use double click on the file.

I would like to recommend you to use OpenFileDialog control on the issue. The OpenFileDialog component allows users to browse the folders of their computer or any computer on the network and select one or more files to open. The dialog box returns the path and name of the file the user selected in the dialog box.

The following code snippet can display the Open File dialog box and call a method to open the file selected by the user.

Code Snippet

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

Dim sr As New System.IO.StreamReader(OpenFileDialog1.FileName)

MessageBox.Show(sr.ReadToEnd)

sr.Close()

End If

End Sub

Please take a look at the following thread can help you further :

Help with Opening text files and pictures in the WebBrowser

Code Snippet

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click

Dim FilePrefix As String = "File://"

If Me.OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then

Me.WebBrowser1.Navigate(FilePrefix & Me.OpenFileDialog1.FileName)

End If

End Sub

Hope that can help you.
BrunoYu-MSFT at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
that means no way to receive the filename from a click in webbrowser component?
BennyLam at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

Benny Lam,

Have you tried to use OpenFileDialog in your application? I believe this is the most simple method on .NET Framework development.

Good luck.

BrunoYu-MSFT at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...