get a file name in openfiledialog

时间:2017-08-05 11:24:31

标签: vb.net openfiledialog

I use OpenFileDialog in VB.NET for importing file from C:\ , but when I choose my file , can I show ONLY the file name (not a complete path ) ? enter image description here

I want to see only namefile.pdf, and not c:....\namefile.pdf

Here is my code:

fichier.Filter = "PDF Files|*.pdf|image files|*.png;*.jpg;*.gif"
If fichier.ShowDialog = DialogResult.OK Then
   fichier_txt.Text = fichier.FileName
End If

fichier is OpenFileDialog name

1 个答案:

答案 0 :(得分:1)

Use Path.GetFileName.

fichier.Filter = "PDF Files|*.pdf|image files|*.png;*.jpg;*.gif"
If fichier.ShowDialog = DialogResult.OK Then
   fichier_txt.Text = Path.GetFileName(fichier.FileName)
End If