What is the correct way to check if a path is an UNC path or a local path?

后端 未结 6 765
说谎
说谎 2020-12-15 04:09

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

6条回答
  •  囚心锁ツ
    2020-12-15 04:32

    Try this extension method:

    public static bool IsUncPath(this string path)
    {
        return Uri.TryCreate(path, UriKind.Absolute, out Uri uri) && uri.IsUnc;
    }
    

提交回复
热议问题