VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-program-to-get-extension-of-a-given-file/

⇱ C# Program to Get Extension of a Given File - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# Program to Get Extension of a Given File

Last Updated : 16 Feb, 2022

DirectoryInfo class provides different types of methods and properties that are used to perform operations on directories and sub-directories like creating, moving, etc. This class has an Extension property which is used to find the extension part from the given file name which includes the dot format in the file's full name. For example, if the file name is c:\gfg.txt, then this property will return ".txt".

Syntax:

public string Extension { get; }

Return: It will return a string with an extension in the dot format of the current file. Even if it is the full file name or an empty string, or if no extension is available. 

Example:

Output:

File extension : .txt
File extension : .pdf
File extension : 
File extension : .txt
Comment
Article Tags:
Article Tags:

Explore