Return file name without extension from full path in C #

I am looking for a way to return fileName from the full path, but without the extension.

private static string ReturnFileNameWithoutExtension(string varFullPathToFile) { string fileName = new FileInfo(varFullPathToFile).Name; string extension = new FileInfo(varFullPathToFile).Extension; return fileName.Replace(extension, ""); } 

Is there still a bulletproof solution, and then replace the extension with an empty string?

+7
source share
4 answers
 return Path.GetFileNameWithoutExtension (fullpath); 
+29
source

I am using System.IO.Path.GetFileNameWithoutExtension(filename);

+6
source
+3
source

Another solution

 string fileName = new FileInfo(varFullPathToFile).Name; fileName=fileName.Substring(0, fileName.LastIndexOf(".")); 
0
source

All Articles