Introduction of C# Path
In this article I will discuss about the uses of C# Path type.
C# path is a name of a directory which identify a unique location of a file in a file system. A path of A file system is expressed in a string of character. The path component is separated by a delimiting character. There are complications when dealing directly with paths. The .NET Framework provides effective ways of dealing with filenames and paths. It introduces the Path type in the System.IO namespace.
static void Main()
string path = "C:\\rahul.txt";
string extension = Path.GetExtension(path);
string filename = Path.GetFileName(path);
string filenameNoExtension = Path.GetFileNameWithoutExtension(path);
string root = Path.GetPathRoot(path);
The output of following program
In this example, we take the extension of the file, the actual filename, the filename without the extension, and the path root. The path root will always be "C:\\", with the trailing separator, even when the file is nested in many folders. GetFileName. You can get the filename alone by calling the Path.GetFileName method.