

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Path methods in C#
To handle File Paths in C#, use the Path methods. These methods come under System.IO Namespace.
Some of them are −
GetExtension
Retrieve the extension of the file using the GetExtension() method.
For example, .txt, .dat, etc.
GetFileName
Retrieve the name of the file using the GetFileName() method.
For example, new.txt, details.dat, etc.
GetFileNameWithoutExtension
Retrieve the name of the file without extension using the GetFileNameWithoutExtension() method.
For example, new, details, etc.
Let us see an example −
Example
using System.IO; using System; class Program { static void Main() { string myPath = "D:\\one.txt"; string fileExtension = Path.GetExtension(myPath); string fileName = Path.GetFileName(myPath); string noExtension = Path.GetFileNameWithoutExtension(myPath); Console.WriteLine("File Extension: "+fileExtension); Console.WriteLine("Fine Name: "+fileName); Console.WriteLine("File Name without extension: "+noExtension); } }
Output
File Extension: .txt Fine Name: D:\one.txt File Name without extension: D:\one
- Related Questions & Answers
- Difference between Test-Path and Resolve-Path in PowerShell?
- How to Move an Element in a Circular Path with CSS offset-path (Motion Path)?
- Path Testing & Basis Path Testing with Example
- Path Sum in Python
- Simplify Path in Python
- Coin Path in C++
- Static methods vs Instance methods in Java
- Min Cost Path
- Methods in Java
- Get an Absolute Filename Path from a Relative Filename Path in Java
- Shortest path algorithms in Javascript
- Display path separator in Java
- Path Sum III in C++
- Minimum Path Sum in C++
- Minimum Path Sum in Python
Advertisements