假设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);
}