24 February, 2010
0 Comments
0 categories
If you want to determine if a given path is a relative path in C#, you can use the System.IO.Path.IsPathRooted function:
bool isPathRooted = Path.IsPathRooted("Test.txt"); Console.WriteLine(isPathRooted);
Result: False
bool isPathRooted = Path.IsPathRooted(@"\\nas\Test.txt"); Console.WriteLine(isPathRooted);
Result: True
bool isPathRooted = Path.IsPathRooted(@"C:\Test.txt"); Console.WriteLine(isPathRooted);
Result: True
Tags: C#