C# Path GetPathRoot

Description

Path GetPathRoot Gets the root directory information of the specified path.

Syntax

Path.GetPathRoot has the following syntax.


public static string GetPathRoot(
  string path
)

Parameters

Path.GetPathRoot has the following parameters.

  • path - The path from which to obtain root directory information.

Returns

Path.GetPathRoot method returns The root directory of path, such as "C:\", or null if path is null, or an empty string if path does not contain root directory information.

Example

The following code example demonstrates a use of the GetPathRoot method.


// www.  ja va 2 s.  c om

using System;
using System.IO;
public class MainClass{
  public static void Main(String[] argv){  
    string fullPath = @"C:\mydir\myfile.ext";
    string pathRoot;
    pathRoot = Path.GetPathRoot(fullPath);
    Console.WriteLine(pathRoot);
  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter