Iain
Iain

Reputation: 2550

How do I convert a path with a drive letter to a UNC path

How do I convert a path with a drive letter like W:\Path\Share to the equivalent unc path like \\server\Share\File in .Net?

At the command prompt you can run net use and that will list the mappings. How do I get at that info in .Net?

Upvotes: 13

Views: 12761

Answers (3)

On Freund
On Freund

Reputation: 4436

You can use P/Invoke and call on a native function such as WNetGetUniversalName.

Upvotes: 6

goku_da_master
goku_da_master

Reputation: 4317

To answer your question about net use here is a good solution Get UNC Path for Mapped Drive VB.net

I like the net use way.

Upvotes: 0

Enrico Campidoglio
Enrico Campidoglio

Reputation: 59973

To get a list of the shared folders on the current machine in .NET you have to options:

Note that the calling process will have run in the context of a user with administrative privileges for this to work.

Upvotes: 2

Related Questions