选择文件时从文本框中删除文件路径 C# Visual Studio

Remove path to file from textbox when file selected C# Visual Studio

你好,我正在尝试从我的 Windows 表单应用程序的目录中 select 一个文件,但我似乎找不到任何可以从文本框中删除路径并保留的内容只有文件名(例如:"C:\Users\Users\Documents\File.txt" 将只是 "File.txt")当文件被 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;
         }

谁能告诉我如何做到这一点?

谢谢

您可以为此使用 Path.GetFileName 函数。

 textBox6.Text = System.IO.Path.GetFileName(openFileDialog1.FileName);