|
-
Feb 7th, 2006, 09:32 PM
#1
Thread Starter
PowerPoster
[RESOLVED] CommonDialog Open and Network Path
I need to run a CommonDialog Open box to get name of a file on the network from the user, but I'll need the network path (\\server\path\filename), not the mapped path (Z:\filename), since I'm saving the file name for some other user to use at a later time, and different departments are mapped differently. (I know it would be more elegant if everyone on the network was mapped the same, but I don't have the luxury of telling the admin how to run his network.)
I know I can, say, open a file with either the mapped path or the network path, but for some reason I'm drawing a blank in how to get cdlg to give me a network path when the user clicks on a file. An API I'm forgetting?
-
Feb 7th, 2006, 09:44 PM
#2
Re: CommonDialog Open and Network Path
This worked for me just now:
VB Code:
Private Sub cmdOpen_Click()
' CancelError is True.
On Error GoTo ErrHandler
CommonDialog1.InitDir = "\\w2k\c550" ' this is the network drive
' Set Flags
CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNLongNames
' Set filters.
CommonDialog1.Filter = "All Files (*.*)|*.*|Text" & _
"Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
' Specify default filter.
CommonDialog1.FilterIndex = 2 ' Default to TEXT
' Display the Open dialog box.
CommonDialog1.ShowOpen
' Call the open file procedure.
' OpenFile (CommonDialog1.FileName)
Debug.Print CommonDialog1.FileName
Exit Sub
ErrHandler:
' User pressed Cancel button.
Exit Sub
End Sub
-
Feb 7th, 2006, 09:57 PM
#3
Re: CommonDialog Open and Network Path
You can use the WNetGetConnection function to translate a mapped path into an UNC path.
VB Code:
Private Declare Function WNetGetConnection _
Lib "mpr.dll" Alias "WNetGetConnectionA" ( _
ByVal lpszLocalName As String, _
ByVal lpszRemoteName As String, _
ByRef cbRemoteName As Long _
) As Long
Public Function GetUNC(ByVal sMappedPath As String) As String
Const MAX_PATH As Long = 260&
Dim sUNC As String
sUNC = String$(MAX_PATH, vbNullChar)
If WNetGetConnection(sMappedPath, sUNC, MAX_PATH) = 0 Then
'Success
GetUNC = Left$(sUNC, InStr(sUNC, vbNullChar) - 1)
End If
End Function
-
Feb 7th, 2006, 11:53 PM
#4
Thread Starter
PowerPoster
Re: [RESOLVED] CommonDialog Open and Network Path
Thank you both. Either solution works nicely, and I learned a lot tonight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|