On a form create a textbox (txtFilePath), button (btnFilePathBrowse), and OpenFileDialog (ofdFilePath).
Double click on the button and the OpenFileDialog in Design view to create the action scripts
Private Sub btnFilePathBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFilePathBrowse.Click ofdFilePath.Title = "Please Select a File" ofdFilePath.FileName = "" ofdFilePath.InitialDirectory = "C:" ofdFilePath.ShowDialog() End Sub Private Sub ofdFilePath_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ofdFilePath.FileOk Dim sioStream As System.IO.Stream sioStream = ofdFilePath.OpenFile() txtFilePath.Text = ofdFilePath.FileName.ToString() End Sub
private void btnFilePathBrowse_Click(System.Object sender, System.EventArgs e) { ofdFilePath.Title = "Please Select a File"; ofdFilePath.FileName = ""; ofdFilePath.InitialDirectory = "C:"; ofdFilePath.ShowDialog(); } private void ofdFilePath_FileOk(System.Object sender, System.ComponentModel.CancelEventArgs e) { System.IO.Stream sioStream = null; sioStream = ofdFilePath.OpenFile(); txtFilePath.Text = ofdFilePath.FileName.ToString(); }
Last Updated on October 26, 2015