如何将PC中的本地文件路径转换为相对网络或UNC路径?

假设D:\myfolder本地路径与\\192.157.1.1\myfolder共享

根据输入中不同类型的路径,调用Path.GetPathRoot以获取返回值

string GetNetworkPath(string path)
{
    string root = Path.GetPathRoot(path);
    if (string.IsNullOrWhiteSpace(root) || !root.Contains(":"))
    {
        throw new ApplicationException("请传递合法的路径!");
    }
    path = path.Remove(0, root.Length);
    return Path.Combine(@"\\192.157.1.1", path);
}
 

猜你喜欢

转载自blog.csdn.net/qq_28368039/article/details/108569957