System.IO.Path.GetPathRoot解决方法UNC路径解决方法、路径、IO、System

2023-09-04 23:34:47 作者:春日快乐颂

GetPathRoot似乎不支持UNC路径。从下面的code的结果只是被修剪掉file.txt的

GetPathRoot doesn't seem to support UNC paths. The result from the code below is simply trimming off file.txt

string root = Path.GetPathRoot("\\servername.pvt\sub dir\file.txt");

什么是一个好的解决办法?

What is a good workaround?

推荐答案

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

The return value is correct. The root is the share, and not the server! For example:

Path.GetPathRoot(@"\\servername.pvt\sharename\directory\file.txt");

这将返回 @\\ servername.pvt \共享名。服务器名称加上共享名构成了根路径。

This returns @"\\servername.pvt\sharename". The server name plus the share name constitutes the path root.