C# Path IsPathRooted

Description

Path IsPathRooted Gets a value indicating whether the specified path string contains a root.

Syntax

Path.IsPathRooted has the following syntax.


public static bool IsPathRooted(
  string path
)

Parameters

Path.IsPathRooted has the following parameters.

  • path - The path to test.

Returns

Path.IsPathRooted method returns true if path contains a root; otherwise, false.

Example

The following code example demonstrates how the IsPathRooted method can be used to test three strings.


//w  w w . j a  va  2 s  .  c  o  m
using System;
using System.IO;
public class MainClass
{
    public static void Main(String[] argv)
    {
        string fileName = @"C:\mydir\myfile.ext";
        bool result;

        result = Path.IsPathRooted(fileName);
        Console.WriteLine(result);

    }
}

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