Get File Name Without Extension in C#.Net
Here we will write code to get the file name without extension using c#.net.
string path = "C:\\DB\\EmployeeDB.db";
string fileName = Path.GetFileNameWithoutExtension(path);
Console.WriteLine(fileName);
Console.ReadLine();
In above code I have declared a variable of string type which is holding the path of the file. In this example I have not validated file exists or not. You must validate file exists or not before performing any file operation. Now let's put a break point and check the output.string path = "C:\\DB\\EmployeeDB.db";
string fileName = Path.GetFileName(path);
Console.WriteLine(fileName);
Console.ReadLine();
In above code I have take a variable in string of string type, which is having file path. This variable I have passed in Path.GetFileName(path) to get the file name with extension. As mentioned earlier you must validate your folder and file before performing any operation. Now let's put a break point and run the code to check the output.