Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Path.IsPathRooted Method

Gets a value indicating whether the specified path string contains absolute or relative path information.

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)

public static bool IsPathRooted (
	string path
)
public static boolean IsPathRooted (
	String path
)
public static function IsPathRooted (
	path : String
) : boolean
Not applicable.

Parameters

path

The path to test.

Return Value

true if path contains an absolute path; otherwise, false.

Exception typeCondition

ArgumentException

path contains one or more of the invalid characters defined in GetInvalidPathChars.

This method does not verify that the path or file name exists.

IsPathRooted returns true for path strings such as "\\MyDir\\MyFile.txt" and "C:\\MyDir". It returns false for path strings such as "MyDir".

For a list of common I/O tasks, see Common I/O Tasks.

The following code example demonstrates a use of the IsPathRooted property.

string fileName = @"C:\mydir\myfile.ext";
string UncPath = @"\\myPc\mydir\myfile";
string relativePath = @"mydir\sudir\";
bool result;

result = Path.IsPathRooted(fileName);
Console.WriteLine("IsPathRooted('{0}') returns {1}", 
    fileName, result);

result = Path.IsPathRooted(UncPath);
Console.WriteLine("IsPathRooted('{0}') returns {1}", 
    UncPath, result);

result = Path.IsPathRooted(relativePath);
Console.WriteLine("IsPathRooted('{0}') returns {1}", 
    relativePath, result);

// This code produces output similar to the following:
//
// IsPathRooted('C:\mydir\myfile.ext') returns True
// IsPathRooted('\\myPc\mydir\myfile') returns True
// IsPathRooted('mydir\sudir\') returns False

String fileName = "C:\\mydir\\myfile.ext";
String UncPath = "\\\\myPc\\mydir\\myfile";
String relativePath = "mydir\\sudir\\";
boolean result;

result = Path.IsPathRooted(fileName);
Console.WriteLine("IsPathRooted('{0}') returns {1}", 
    fileName, System.Convert.ToString(result));

result = Path.IsPathRooted(UncPath);
Console.WriteLine("IsPathRooted('{0}') returns {1}", 
    UncPath, System.Convert.ToString (result));

result = Path.IsPathRooted(relativePath);
Console.WriteLine("IsPathRooted('{0}') returns {1}", 
    relativePath, System.Convert.ToString (result));

var fileName : String = "C:\\mydir\\myfile.ext";
var UncPath : String = "\\\\myPc\\mydir\\myfile";
var relativePath : String = "mydir\\sudir\\";
var result : boolean;

result = Path.IsPathRooted(fileName);
Console.WriteLine("IsPathRooted('{0}') returns {1}", 
                  fileName, result);

result = Path.IsPathRooted(UncPath);
Console.WriteLine("IsPathRooted('{0}') returns {1}", 
                  UncPath, result);

result = Path.IsPathRooted(relativePath);
Console.WriteLine("IsPathRooted('{0}') returns {1}", 
                  relativePath, result);

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

Show:
© 2014 Microsoft