Thanks, Ranjan.
I am working on a distributed application. When a user specifies a file in
the application, I need to determine if other users will be able to see the
file in its original location.
So I am converting all reference paths to UNC paths. But if the users
specifies a file in a directory that is not shared, UNC does not work. Or if
the user specifies a file in a special directory like "My Pictures" or
"Shared Pictures" UNC does not work because the file sharename is unique.
Here is my function to convert local path to UNC:
Public Function GetUNCPathFrom(ByVal Path As String) As String
Try
Dim fso As New Scripting.FileSystemObject
Dim drive As Scripting.Drive
drive = fso.GetDrive(fso.GetDriveName(Path))
If drive.DriveType = Scripting.DriveTypeConst.Remote Then
'remote drive
If Path.StartsWith(drive.ShareName) Then
'the user navigated to Windows Network, Machine, share
'then the path will be UNC path
Return Path
Else
'the user navigated to mapped drive
'build the UNC from drive share name and path (remove the drive
letter and ":")
Return drive.ShareName & Path.Remove(0, 2)
End If
Else
'local drive
'convert to UNC path, remove drive letter and ":" from path
'THIS DOESN'T WORK FOR SPECIAL FOLDERS
Return "\\" & Environment.MachineName & Path.Remove(0, 2)
End If
Catch ex As Exception
LogError(Now, ex.ToString)
End Try
End Function