Determine if directory is shared in VB.NET?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Is there a way to programmatically determine if a directory is shared and if
so, what the sharename is?

It seems a simple question, but I have been searching and not found the
answer...

Thanks in advance!
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top