UNC Conversion

  • Thread starter Thread starter Andy Rotering
  • Start date Start date
A

Andy Rotering

Hi,

Does .NET have a function that will convert from a local path to a UNC path?

Thanks!

Andy
 
I'm guessing you'd need to access the NetAPI to find out what shares exist
on the computer, and then present a choice. On NT machines, you'll see that
each drive is shared as X$, where X is the drive letter. So, you could
remove the root (X:\) and replace with \\machinename\X$\ .

-mike
MVP
 
Hi Andy,

Thanks for your post. I agree with Mike that you will need to call
unmanaged APIs to get the UNC name of a folder.

In addition, if the folder is already shared explicitly, we are able to
call WNetEnumResource to enumerate the network resources to get its UNC.
You can use P/Invoke in your managed .NET application to call
WNetEnumResource() API to determine to which a specific local name is
mapped to a remote name of a shared folder. I believe the following article
and sample are helpful:

WNetEnumResource API
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wnet/wnet/w
netenumresource.asp

WNetEnumResource sample
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=741&lngW
Id=10

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi,

Does .NET have a function that will convert from a local path to a UNC path?

Thanks!

Andy

Thanks for your feedback. The function that I was looking for is
WNetGetUniversalName. This function takes in a local path and gives
you a UNC path.

Thanks again.
 
Only if the local path is a share though. If you try it out with
C:\Something.txt, it'll give you ERROR_NOT_CONNECTED.
-mike
MVP
 
Back
Top