有人可以告诉我如何只显示名称而不是名称前面的完整路径.我发现这个代码只显示扩展名或只显示没有扩展名的文件名.我想要显示的是具有扩展名的文件的名称.
像这样: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));
}
Run Code Online (Sandbox Code Playgroud)
谢谢大家的帮助
Mar*_*cus 13
var onlyfilename = Path.GetFileName(openFileDialog1.FileName);
Run Code Online (Sandbox Code Playgroud)