Obtaining only the filename when using OpenFileDialog property “FileName”

后端 未结 2 1733
终归单人心
终归单人心 2020-12-03 04:23

I am trying to include only the filename of the file I\'ve selected in the OpenFileDialog in the label1.Text property, but I haven\'t found a solution yet. I know I could us

相关标签:
2条回答
  • 2020-12-03 04:42

    Use: Path.GetFileName Method

    var onlyFileName = System.IO.Path.GetFileName(ofd.FileName);
    
    0 讨论(0)
  • 2020-12-03 05:02

    Use OpenFileDialog.SafeFileName

    OpenFileDialog.SafeFileName Gets the file name and extension for the file selected in the dialog box. The file name does not include the path.

    0 讨论(0)
提交回复
热议问题