您当前的位置: 首页 >  网络

君子居易

暂无认证

  • 0浏览

    0关注

    210博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

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

君子居易 发布时间:2020-09-13 23:03:14 ,浏览量:0

假设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);
}
 
关注
打赏
1660814979
查看更多评论
立即登录/注册

微信扫码登录

0.0378s