The easiest way to check if a path is an UNC path is of course to check if the first character in the full path is a letter or backslash. Is this a good solution or could th
This is my version:
public static bool IsUnc(string path)
{
string root = Path.GetPathRoot(path);
// Check if root starts with "\\", clearly an UNC
if (root.StartsWith(@"\\"))
return true;
// Check if the drive is a network drive
DriveInfo drive = new DriveInfo(root);
if (drive.DriveType == DriveType.Network)
return true;
return false;
}
The advantage of this version over @JaredPars version is that this supports any path, not just DriveInfo
.