473,698 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determine if directory is shared in VB.NET?

KSC
Hello,

Is there a way to programmaticall y 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 6812
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 programmaticall y 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.FileS ystemObject
Dim drive As Scripting.Drive
drive = fso.GetDrive(fs o.GetDriveName( Path))
If drive.DriveType = Scripting.Drive TypeConst.Remot e Then
'remote drive
If Path.StartsWith (drive.ShareNam e) 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.Mac hineName & 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 programmaticall y 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.manageme nt 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.FileS ystemObject
Dim drive As Scripting.Drive
drive = fso.GetDrive(fs o.GetDriveName( Path))
If drive.DriveType = Scripting.Drive TypeConst.Remot e Then
'remote drive
If Path.StartsWith (drive.ShareNam e) 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.Mac hineName & 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 programmaticall y 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
5306
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. the used OS te determine are: win 95, win 98, win ME, win XP, win NT Thanks for help,
0
1679
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 drive using the win32 Api and using the handle returned, i call writefile giving number of bytes to write as 1MB. Shared directory on the machine maps to F: drive ( "shared" is the directory name maps to " F:") In VC6 on executing...
4
3706
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 Directory.GetFileSystemEntries(path), but I would like to know how to put this together, knowing which entry is a Subdirectory and which entry is a file, and make a recursive list of the Directory structure below a specific path - - -
27
2551
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: Mensaje de error del analizador: We can't load the type 'JULIAN.Global'.
2
2196
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 does not work, although I can through code open and copy files from "\Docs"
0
945
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 deserialized upon startup. I'd like to automatically refresh the state of my objects when other users have changed their state through this same persisted file. What is the best way to determine when this has happened ? Continually run a timer...
1
1074
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
20615
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 that does not resort to all the lowlevel ugliness of os.stat() AND that is portable across Win32 and *nix? Thanks, ---------------------------------------------------------------------------- Tim Daneliuk tundra@tundraware.com PGP Key: ...
12
6611
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 degrade if not available. (Specifically, I want to use System.Windows.Media.Imaging.BitmapMetadata to extract metadata from JPEG files when 3.0 is available, but will resort to System.Drawing.Image if .NET 3.0 is not installed.) What is the...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.