Return FileName Only when using OpenFileDialog

后端 未结 8 784
孤独总比滥情好
孤独总比滥情好 2020-12-06 04:34

I am using the following method to browse for a file:

    OpenFileDialog.ShowDialog()
    PictureNameTextEdit.Text = OpenFileDialog.FileName
<
相关标签:
8条回答
  • 2020-12-06 04:45

    Suppose that I did select word2010 file named as "MyFileName.docx"

    This is for ONLY the selected file extension "including the dot mark, f.e (.docx)"

    MsgBox(System.IO.Path.GetExtension(Opendlg.FileName))
    

    And this for the selected File name without extension: (MyFileName)

    MsgBox(System.IO.Path.GetFileNameWithoutExtension(Opendlg.FileName))
    

    and you can try the other options for the "PATH Class" like: GetFullPath,GetDirectoryName ...and so on.

    0 讨论(0)
  • 2020-12-06 04:58

    Use SafeFileName instead of FileName and it will return a name (and extension) without path.

    0 讨论(0)
  • 2020-12-06 04:59

    if you want just the selected name without Extension you can try this code

    Imports System.IO
    
    
    PictureNameTextEdit.Text = Path.GetFileNameWithoutExtension(OpenFileDialog1.Fi‌​leName)
    

    thanx

    0 讨论(0)
  • 2020-12-06 05:01

    Use Path.GetFileName(fullPath) to get just the filename part, like this:

    OpenFileDialog.ShowDialog()
    PictureNameTextEdit.Text = System.IO.Path.GetFileName(OpenFileDialog.FileName)
    
    0 讨论(0)
  • 2020-12-06 05:04

    Use this code to put the filename in PictureNameTextEdit:

    OpenFileDialog.ShowDialog()
    PictureNameTextEdit.Text = OpenFileDialog.SafeFileName
    
    0 讨论(0)
  • 2020-12-06 05:08
    OpenFileDialog.ShowDialog()
    PictureNameTextEdit.Text = System.IO.Path.GetFileName(OpenFileDialog.FileName)
    
    0 讨论(0)
提交回复
热议问题