
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# program to get the extension of a file in C#
To handle file paths, the Path class is used in C#.
Set the file name in a string −
string myPath = "D:\
ew\quiz.txt";
Now, to get the extension, use the GetExtension() method −
Path.GetExtension(myPath)
Here is the complete code −
Example
using System; using System.IO; namespace Demo { class Program { static void Main(string[] args) { string myPath = "D:\
ew\quiz.txt"; Console.WriteLine(Path.GetExtension(myPath)); } } }
Output
.txt
- Related Articles
- Golang program to get the file extension
- How to get file extension of file as a result of MySQL query?
- How to get the file extension using PowerShell?
- Get file extension name in Java
- Get only the file extension from a column with file names as strings in MySQL?
- Perl File Extension
- How to change file extension in Python?
- How to extract file extension using Python?
- C# Program to get the last write time of a file
- C# Program to get the last access time of a file
- Insert a word before the file name’s dot extension in JavaScript?
- Change the file extension in the text column in MySQL?
- How to trim a file extension from a string using JavaScript?
- C# program to get the file name in C#
- C# Program to get information about a file

Advertisements