473,378 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Determine if directory is shared in VB.NET?

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
3 6784
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: lucpustjens | last post by:
Hello, I want te determine the client operating system, because I need to kno the default cookie directory. If there is a way to determine the cooki directory directly, than it is also good. ...
0
by: Nitin Narang | last post by:
I have a piece of code which is moved to .NET VC7 recently from VC6 and there has been an apparent change in behavior using CreateFile/Writefile functionality. I am creating a file on a shared...
4
by: Elmo Watson | last post by:
Is there a way, with the System.IO class, to do a recursive list of a directory structure? For instance, in DirectoryInfo, you have GetDirectories and GetFiles .... In Directory, you have...
27
by: Javier Martinez | last post by:
Hi I have asp application in a machine with a virtual directory referring a shared directory in another machine When I try to load any aspx page of my portal I get the following error: ...
2
by: Paul Bromley | last post by:
How can I create a directory within a shared ntwork directory?? sServerName - is the Server name "\Docs" - is the shared directory "\Others" - is the directory to create. The following...
0
by: marfi95 | last post by:
Basically, I keep the state of some objects serialized in an xml file through the use of a data set. The xml file serialized is persisted onto a shared network drive. However, the file is only...
1
by: KSC | last post by:
Hello, Is there a way to programmatically determine if a file is contained in a shared directory? It seems a simple question, but I have not been able to find a way to do this... Thanks!
28
by: Tim Daneliuk | last post by:
I have a program wherein I want one behavior when a file is set as executable and a different behavior if it is not. Is there a simple way to determine whether a given named file is executable...
12
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
I am writing a web app to be widely distributed where I do not know the installed .NET Framework version. I want to take advantage of some .NET 3.0 classes if they are installed, but gracefully...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.