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.

[Visual Basic]
Public Shared Function IsPathRooted( _
   ByVal path As String _
) As Boolean
[C#]
public static bool IsPathRooted(
 string path
);
[C++]
public: static bool IsPathRooted(
 String* path
);
[JScript]
public static function IsPathRooted(
   path : String
) : Boolean;

Parameters

path
The path to test.

Return Value

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

Exceptions

Exception Type Condition
ArgumentException path contains one or more of the invalid characters defined in InvalidPathChars.

Remarks

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 an example of using this method, see the Example section below. The following table lists examples of other typical or related I/O tasks.

To do this... See the example in this topic...
Create a text file. Writing Text to a File
Write to a text file. Writing Text to a File
Read from a text file. Reading Text from a File
Retrieve the fully qualified path of a file. GetFullPath
Retrieve only the directory name from a path. GetDirectoryName
Determine if a directory exists. Exists

Example

[Visual Basic, C#, C++] The following example demonstrates a use of the IsPathRooted property.

[Visual Basic] 
Dim fileName As String = "C:\mydir\myfile.ext"
Dim UncPath As String = "\\myPc\mydir\myfile"
Dim relativePath As String = "mydir\sudir\"
Dim result As 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)

[C#] 
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);

[C++] 
String * fileName = S"C:\\mydir\\myfile.ext";
String * UncPath = S"\\\\myPc\\mydir\\myfile";
String * relativePath = S"mydir\\sudir\\";
bool result;

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

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

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Path Class | Path Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File

Show:
© 2015 Microsoft