Friday, January 27, 2012

Get file extention, file path, file name , file Extension in ASP.Net


using System;
using System.IO;

class Program
{
    static void Main()
    {
string path = "C:\\stagelist.txt";

string extension = Path.GetExtension(path);
string filename = Path.GetFileName(path);
string filenameNoExtension = Path.GetFileNameWithoutExtension(path);
string root = Path.GetPathRoot(path);

Console.WriteLine("{0}\n{1}\n{2}\n{3}",
   extension,
   filename,
   filenameNoExtension,
   root);
    }
}

Output

.txt
stagelist.txt
stagelist
C:\

No comments: