UNC路径的System.IO.Path.GetPathRoot变通方法

sil*_*one 0 .net

GetPathRoot似乎不支持UNC路径.以下代码的结果只是修剪file.txt

string root = Path.GetPathRoot("\\servername.pvt\sub dir\file.txt");
Run Code Online (Sandbox Code Playgroud)

什么是好的解决方法?

cdh*_*wie 7

返回值是正确的.根是共享,而不是服务器!例如:

Path.GetPathRoot(@"\\servername.pvt\sharename\directory\file.txt");
Run Code Online (Sandbox Code Playgroud)

这回来了@"\\servername.pvt\sharename".服务器名称加上共享名称构成路径根.