Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
C# program to get the file name in C#
Set the path name in a string −
string myPath = "D:\
ew\quiz.txt";
Now, use the GetFileName() method to get the name of the file −
Path.GetFileName(myPath)
The following 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";
// get extension
Console.WriteLine("Extension: "+Path.GetExtension(myPath));
// get path
Console.WriteLine("File Path: "+Path.GetFileName(myPath));
}
}
}
Output
Extension: .txt File Path: D:
ew\quiz.txt
Advertisements