Translate drive letter to UNC for mapped drives

  • Thread starter Thread starter Michael Russell
  • Start date Start date
M

Michael Russell

Hi, I'm converting a C++ program over to C# (on .Net 2.0), and am not
sure of the best way to look up the UNC path for mapped drives.

The way the C++ program does this is it iterates through a listing of
drive letters, then calls WNetGetUniversalName for each to get the UNC.
.Net 2.0 seems to have a fairly broad selection of IO handling
options, but I've not yet found one to handle my problem.

Any pointers?
 
Michael,

.NET doesn't have anything to handle this out of the box. However, you
can call the WNetGetUniversalName API through the P/Invoke layer if you
wish.

Hope this helps.
 
Like Nicholas said, you should use WNetGetUniversalName. Here's a code
snippet that shows how to use P/Invoke to get the UNC path:

http://groups.google.com/group/micr...b3b76?lnk=st&q=&rnum=1&hl=en#71e214768a2b3b76

Michael,

.NET doesn't have anything to handle this out of the box. However, you
can call the WNetGetUniversalName API through the P/Invoke layer if you
wish.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Michael Russell said:
Hi, I'm converting a C++ program over to C# (on .Net 2.0), and am not sure
of the best way to look up the UNC path for mapped drives.

The way the C++ program does this is it iterates through a listing of
drive letters, then calls WNetGetUniversalName for each to get the UNC.
.Net 2.0 seems to have a fairly broad selection of IO handling options,
but I've not yet found one to handle my problem.

Any pointers?
 
John said:
Like Nicholas said, you should use WNetGetUniversalName. Here's a code
snippet that shows how to use P/Invoke to get the UNC path:

http://groups.google.com/group/micr...b3b76?lnk=st&q=&rnum=1&hl=en#71e214768a2b3b76

Michael,

.NET doesn't have anything to handle this out of the box. However, you
can call the WNetGetUniversalName API through the P/Invoke layer if you
wish.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Michael Russell said:
Hi, I'm converting a C++ program over to C# (on .Net 2.0), and am not sure
of the best way to look up the UNC path for mapped drives.

The way the C++ program does this is it iterates through a listing of
drive letters, then calls WNetGetUniversalName for each to get the UNC.
.Net 2.0 seems to have a fairly broad selection of IO handling options,
but I've not yet found one to handle my problem.

Any pointers?

Thanks John and Nicholas. A little disappointing that there isn't
something built-in, but I appreciate the confirmation and the link to
the code snippet.

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top