从本地路径或映射路径获取UNC路径 [英] Get UNC path from a local path or mapped path

查看:96
本文介绍了从本地路径或映射路径获取UNC路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Delphi中,有一个ExpandUNCFileName函数,该函数接受文件名并将其转换为等效的UNC.它会扩展映射的驱动器,并跳过本地和已经扩展的位置.

In Delphi there is a function ExpandUNCFileName that takes in a filename and converts it into the UNC equivalent. It expands mapped drives and skips local and already expanded locations.

样品

C:\ Folder \ Text.txt-> C:\ Folder \ Text.txt
L:\ Folder \ Sample.txt-> \\ server \ Folder1 \ Folder \ Sample.txt其中L:映射到\\ server \ Folder1 \
\\ server \ Folder \ Sample.odf-> \ server \ Folder \ Sample.odf

C:\Folder\Text.txt -> C:\Folder\Text.txt
L:\Folder\Sample.txt -> \\server\Folder1\Folder\Sample.txt Where L: is mapped to \\server\Folder1\
\\server\Folder\Sample.odf -> \server\Folder\Sample.odf

是否有一种简单的方法可以在C#中执行此操作?还是我必须使用Windows api调用WNetGetConnection,然后手动检查那些不会被映射的内容?

Is there a simple way to do this in C# or will I have to use windows api call WNetGetConnection and then manually check the ones that wouldn't get mapped?

推荐答案

BCL中没有内置函数可以执行等效操作.我认为您最好的选择就是按照您的建议将其调用到WNetGetConnection中.

There is no built-in function in the BCL which will do the equivalent. I think the best option you have is pInvoking into WNetGetConnection as you suggested.

这篇关于从本地路径或映射路径获取UNC路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆