Results 1 to 3 of 3

Thread: Unc

  1. #1
    Join Date
    Jun 2003

    Unhappy Unanswered: Unc

    In the past, I have used the active X object COMDLG32.ocx to create an easy way for my clients to specify an existing file.
    In a new application that I'm creating (trying to...), I need to get a path to a file (indicated by the user) but only the directory. Normally, I could use that Common Dialog object again but this time, I need to get the path in UNC instead of the usual format; so something like "\\MyServer\MyDirectory\MySubDirectory\MyFile. txt"

    Anyone has any experience on this?
    I'll appreciate any help on this matter!

  2. #2
    Join Date
    Aug 2003
    You could convert the recieved path to unc. Maybe you could use this code.

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

    Public Function fGetUNCDrive(strDrive As String)

    Dim lngReturn As Long
    Dim lngLength As Long
    Dim uncDrive As String

    uncDrive = String$(255, 0)
    lngLength = Len(uncDrive)
    lngReturn = WNetGetConnection(strDrive, uncDrive, lngLength)
    uncDrive = Left(uncDrive, InStr(uncDrive, vbNullChar) - 1)
    If Len(uncDrive & "") = 0 Then
    uncDrive = strDrive
    End If
    fGetUNCDrive = uncDrive

    End Function

    Public Function fGetUNCPAth(strPath As String) As String

    Dim strUNCDrive As String

    If Left(strPath , 2) = "\\" Then
    fGetUNCPAth = strPath
    strUNCDrive = fGetUNCDrive(Left(strPath , 2))
    fGetUNCPAth = strUNCDrive & Mid(strPath , 3)
    End If

    End Function

    /Svein Erik

  3. #3
    Join Date
    Jun 2003
    Thanks a lot, Erik

    This works just fine!
    I already found some other snips (also based on the WnetGetConnection or on WnetGetUniversalName) but none of them were what I was looking for.
    At least your code, I can read and understand!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts