Get the file name without extension in C#
To get filename without extension in C# we can simply call methodPath.GetFileNameWithoutExtension()
which takes path as string parameter. Remember to include required namespace: using System.IO;
Example
using System;
using System.IO;
public class Example
{
public static void Main()
{
string path = @"C:\Users\user\desktop\demo.txt";
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(path);
Console.WriteLine(filenameWithoutExtension);
}
}
Output
demo