Hello I am trying to select a file from a directory from my Windows Form application, but I can't seem to find anything that will remove the path from the text box and keep only the file name (Example: "C:\Users\Users\Documents\File.txt" would be just "File.txt") where it saves the output when file is selected.
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = @"C:\OUTPUT";
openFileDialog1.Title = "Browse exe Files";
openFileDialog1.CheckFileExists = true;
openFileDialog1.CheckPathExists = true;
openFileDialog1.Filter = "exe files | *.exe";
openFileDialog1.DefaultExt = "exe";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
openFileDialog1.ReadOnlyChecked = true;
openFileDialog1.ShowReadOnly = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox6.Text = openFileDialog1.FileName;
}
Can anyone enlighten me on how to do this?
Thanks
You can use the Path.GetFileName function for this.