Ask the Expert

How do I get the UNC path from a drive letter in .NET?

How do I get the UNC path from a drive letter in .NET? I tried using the DECLARE wnetgetconnection32 API call, and could not get that working either. Any suggestions?
Keep in mind that WnetGetConnection will only return the UNC path for a mapped drive, not just any drive. The program below will show the UNC name for the mapped Q: drive.
Module Module1

    Public Declare Function WNetGetConnection Lib "mpr.dll" Alias _
             "WNetGetConnectionA" (ByVal lpszLocalName As String, _
             ByVal lpszRemoteName As String, ByRef cbRemoteName As Integer) As 
Integer

    Sub Main()

        Dim ret As Integer
        Dim out As String = New String(" ", 260)
        Dim len As Integer = 260

        ret = WNetGetConnection("Q:", out, len)

        Console.WriteLine(out)
    End Sub

End Module

This was first published in March 2004

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: