Problem solve Get help with specific problems with your technologies, process and projects.

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 

    Sub Main()

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

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

    End Sub

End Module

This was last published in March 2004

Dig Deeper on Win Development Resources

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

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

Please create a username to comment.