DEV Community

Ricardo
Ricardo

Posted on • Originally published at rmauro.dev on

1 1

Getting the file name without extension in C# - #TIP

These days I was asking myself how to get the file name without the extension. I confess I was tempted to use a regex to solve this problem :)

But no worries. There is a method in System.IO.Path specific for this situation.

using System.IO;

///
/// Get file name without extension
///
static string GetFileName(string path)
{
    return Path.GetFileNameWithoutExtension(path);
}

///
/// Get file name without extension
///
static string GetFileName(FileInfo fileInfo)
{
    return Path.GetFileNameWithoutExtension(fileInfo.Name);
}
Enter fullscreen mode Exit fullscreen mode

Credits go for this answer in StackOverflow forum.

Getting file names without extensions

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more