?
Solved

Get UNC path of a network drive

Posted on 2004-04-21
5
Medium Priority
?
1,096 Views
Last Modified: 2007-12-19
How do I get the unc path of a drive letter in VB.Net?


Here is what my function definition should look like:
Public Shared Function fnGetUncPath(ByVal strDriveLetterAs String) As String


This is an example of how the function should work:
?fnGetUncPath("U")
\\SERVER\USERNAME

I have tried unsuccessfully to implement the WNetGetUniversalName api.

Thanks in advance
0
Comment
Question by:eeyore7250
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Expert Comment

by:tgannetts
ID: 10887022
0
 
LVL 7

Accepted Solution

by:
ramesh12 earned 500 total points
ID: 10891759
0
 
LVL 4

Expert Comment

by:MajinLoki
ID: 10892734
I've done this.  Here's how I did it with a sql connection.

Dim connect As sql.SqlConnection
connect = new SqlConnection("connectionString")
connect.Open()

'get the server name
srvr = connect.DataSource()

now, if you know the location of the folder, either by default, or by letting hte user select it by using a dialog, you can use regular expressions to find each folder and then rebuild the UNC

"\\" & srvr & "\foldername"

Hope that helps.

Majin Loki
0
 
LVL 4

Author Comment

by:eeyore7250
ID: 10974133
Public Class clsUnc

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

    Public Shared Function fnGetUncPath(ByVal strDriveLetter As String) As String
        Dim intRet As Integer
        Dim strRet As String = New String(" ", 260)
        Dim intLen As Integer = 260
        intRet = WNetGetConnection(strDriveLetter.Substring(0, 1) & ":", strRet, intLen)
        Return strRet
    End Function
End Class
0
 
LVL 4

Author Comment

by:eeyore7250
ID: 10992074
Actually this code is better:

Public Class clsUnc

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

    Friend Shared Function fnGetUncPath(ByVal strDriveLetter As String) As String
        Dim intRet As Integer
        Dim strRet As String = ""
        Dim strTmp As String = New String(" ", 260)
        Dim intLen As Integer = 260
        Dim intCnt As Integer = 0
        intRet = WNetGetConnection(strDriveLetter.Substring(0, 1) & ":", strTmp, intLen)
        Do Until intCnt = (intLen - 1) Or strTmp.Substring(intCnt + 1, 1) = " "
            strRet &= strTmp.Substring(intCnt, 1)
            intCnt += 1
        Loop
        Return strRet
    End Function
End Class
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question