您好我正在尝试从我的Windows窗体应用程序中的目录中选择一个文件,但我似乎找不到任何会从文本框中删除路径并保留文件名的内容(例如:& #34; C:\ Users \ Users \ Documents \ File.txt"只是" File.txt")在选择文件时保存输出。
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;
}
任何人都可以告诉我如何做到这一点吗?
由于
答案 0 :(得分:4)
您可以使用Path.GetFileName功能。
textBox6.Text = System.IO.Path.GetFileName(openFileDialog1.FileName);