This post will discuss how to get a file name without an extension in C#.

1. Using Path.GetFileNameWithoutExtension() method

We can use the Path.GetFileNameWithoutExtension() method to return the file name without the extension. It returns all the characters in the string returned by Path.GetFileName(), minus the last period (.) and the characters following it. Here’s simple usage of this method:

Download Code

2. Using Path.GetFileName() method

Similar to the Path.GetFileNameWithoutExtension() method implementation, we can even write our utility method to get the filename without extension. The following example illustrates.

Download Code

That’s all about getting the file name without extension in C#.