2016-02-15

Get file extension (C#)

When working with the files, there is inevitable that at the point of time you will need information about file extension. Here is the code:
string fileName = @"C:\temp\file.ext";
string extension;

extension = Path.GetExtension(fileName);
Console.WriteLine("Extension('{0}') returns '{1}'", fileName, extension);
// returns something like:
// GetExtension('C:\temp\file.ext') returns '.ext' 

No comments:

Post a Comment