有人可以告诉我如何只显示名称而不是名称前面的完整路径。我发现此代码仅显示扩展名或仅显示不带扩展名的文件名。我想要显示的是带有扩展名的文件的名称。
像这样:example.txt。
代码:
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Binary Files (.BIN; .md6; .md7)|*.BIN; *.md6; *.md7|All Files (*.*)|*.*";
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
System.IO.StreamReader sr = new
System.IO.StreamReader(openFileDialog1.FileName);
sr.Close();
}
}
String filedata = openFileDialog1.FileName;
openFileDialog1.Title = ("Choose a file");
openFileDialog1.InitialDirectory = "C:\\Projects\\flashloader2013\\mainapplication\\Bootfiles";
//textBox1.Text = (System.IO.Path.GetExtension(openFileDialog1.FileName));
textBox1.Text = (System.IO.Path.Get(openFileDialog1.FileName));
}
谢谢大家的帮助