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();
}
Originally Posted on December 18, 2013
Last Updated on October 26, 2015
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.