पथ नाम को स्ट्रिंग में सेट करें:
string myPath = "D:\\new\\quiz.txt";
अब, फ़ाइल का नाम प्राप्त करने के लिए GetFileName() मेथड का उपयोग करें:
Path.GetFileName(myPath)
निम्नलिखित पूरा कोड है:
उदाहरण
using System; using System.IO; namespace Demo { class Program { static void Main(string[] args) { string myPath = "D:\\new\\quiz.txt"; // एक्सटेंशन प्राप्त करें Console.WriteLine("एक्सटेंशन: "+Path.GetExtension(myPath)); // पथ प्राप्त करें Console.WriteLine("फ़ाइल पथ: "+Path.GetFileName(myPath)); } } }आउटपुट
एक्सटेंशन: .txt फ़ाइल पथ: D:\new\quiz.txt