This question already has an answer here:
I have a save file dialog and i want to get only the filename entered. Equivalent for
openfiledialog.SafeFileName;
Save file dialog has no SafeFileName
Property and FileName
returns both filename, path and extension. Pls how do i extract only file name.
If you want the filename with extension use
Path.GetFileName()
. If you want it without the extension as well usePath.GetFileNameWithoutExtension()
.See MSDN for further details, especially the
Path
class which has a number of useful methods:http://msdn.microsoft.com/en-us/library/System.IO.Path_methods.aspx
http://msdn.microsoft.com/en-us/library/system.io.path.getfilename.aspx
http://msdn.microsoft.com/en-us/library/system.io.path.getfilenamewithoutextension.aspx
Also found another solution to my problem