I am using the following method to browse for a file:
OpenFileDialog.ShowDialog() PictureNameTextEdit.Text = OpenFileDialog.FileName
Is there a way get ONLY the file name?
The FileName method returns the entire path and file name.
i.e. I want Foo.txt instead of C:\SomeDirectory\Foo.txt
OpenFileDialog component opens the Windows dialog box for browsing and selecting files. To open and read the selected files, you can use the OpenFileDialog. OpenFile method, or create an instance of the System. IO.
Use the askopenfilename() function to display an open file dialog that allows users to select one file. Use the askopenfilenames() function to display an open file dialog that allows users to select multiple files.
Use Path.GetFileName(fullPath)
to get just the filename part, like this:
OpenFileDialog.ShowDialog() PictureNameTextEdit.Text = System.IO.Path.GetFileName(OpenFileDialog.FileName)
OpenFileDialog.ShowDialog() PictureNameTextEdit.Text = System.IO.Path.GetFileName(OpenFileDialog.FileName)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With