![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
Advertisements