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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.