By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,691 Members | 1,143 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,691 IT Pros & Developers. It's quick & easy.

Determine if directory is shared in VB.NET?

P: n/a
KSC
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!
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
why do u want to find the shared folder .. if u specify the requirement .. i
can help you
"KSC" wrote:
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!

Nov 21 '05 #2

P: n/a
KSC
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

"Ranjan" wrote:
why do u want to find the shared folder .. if u specify the requirement .. i
can help you
"KSC" wrote:
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!

Nov 21 '05 #3

P: n/a
i think system.management class would be use ful in youir case

"KSC" wrote:
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

"Ranjan" wrote:
why do u want to find the shared folder .. if u specify the requirement .. i
can help you
"KSC" wrote:
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!

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.