How to know the filename when the user clicked?
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!
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!
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.
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
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
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.