473,387 Members | 1,638 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,387 software developers and data experts.

How to get a list of all shared folders?

sva
Using C# for an application in which I am working on, I need to display the
available shared folders on the computer that's running the application.
The shared folder paths need to be in UNC format (i.e., \\servername\share).
I don't need to read, write, edit, delete, etc. any files or folders, I
simply need to get a list of all the shared folders and get their full UNC
path.

I know the System.IO namespace has some methods and/or properties to get
directories, but I don't know how to limit this to only the available shared
folders.

Thanks!
Jan 16 '06 #1
3 26270
I do not know of a managed way to accomplish this. The NetShareEnum()
Win32 function should suffice.

http://msdn.microsoft.com/library/de...tshareenum.asp

http://www.codeproject.com/csharp/networkshares.asp

Jason Newell

sva wrote:
Using C# for an application in which I am working on, I need to display the
available shared folders on the computer that's running the application.
The shared folder paths need to be in UNC format (i.e., \\servername\share).
I don't need to read, write, edit, delete, etc. any files or folders, I
simply need to get a list of all the shared folders and get their full UNC
path.

I know the System.IO namespace has some methods and/or properties to get
directories, but I don't know how to limit this to only the available shared
folders.

Thanks!

Jan 16 '06 #2

"sva" <no****@company.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
| Using C# for an application in which I am working on, I need to display
the
| available shared folders on the computer that's running the application.
| The shared folder paths need to be in UNC format (i.e.,
\\servername\share).
| I don't need to read, write, edit, delete, etc. any files or folders, I
| simply need to get a list of all the shared folders and get their full UNC
| path.
|
| I know the System.IO namespace has some methods and/or properties to get
| directories, but I don't know how to limit this to only the available
shared
| folders.
|
| Thanks!
|
|

I'm not entirely clear on what you are after, are you trying to get a list
of exported shared folders (server side), or are you looking for the mapped
network connections (client side).
Anyway both can be obtained using System.Management and WMI.
Following is a sample illustrates how to get the UNC paths of the exported
shares...

using(ManagementClass exportedShares = new
ManagementClass("Win32_Share" ))
using(ManagementClass computer = new
ManagementClass("Win32_computersystem" ))
{
string localSystem = null;
ManagementObjectCollection localComputer = computer.GetInstances();
foreach(ManagementObject mo in localComputer)
{
localSystem = mo["Name"].ToString();
}
ManagementObjectCollection shares = exportedShares.GetInstances();
foreach(ManagementObject share in shares)
// dump UNC path
Console.WriteLine(@"UNC path \\{0}\{1}", localSystem, share["Name"]);
}

Willy.
Jan 16 '06 #3
sva
Thanks! I'm only trying to get a list of exported shared folders (server
side), and your solution works great.
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:uh**************@TK2MSFTNGP10.phx.gbl...

"sva" <no****@company.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
| Using C# for an application in which I am working on, I need to display
the
| available shared folders on the computer that's running the application.
| The shared folder paths need to be in UNC format (i.e.,
\\servername\share).
| I don't need to read, write, edit, delete, etc. any files or folders, I
| simply need to get a list of all the shared folders and get their full UNC | path.
|
| I know the System.IO namespace has some methods and/or properties to get
| directories, but I don't know how to limit this to only the available
shared
| folders.
|
| Thanks!
|
|

I'm not entirely clear on what you are after, are you trying to get a list
of exported shared folders (server side), or are you looking for the mapped network connections (client side).
Anyway both can be obtained using System.Management and WMI.
Following is a sample illustrates how to get the UNC paths of the exported
shares...

using(ManagementClass exportedShares = new
ManagementClass("Win32_Share" ))
using(ManagementClass computer = new
ManagementClass("Win32_computersystem" ))
{
string localSystem = null;
ManagementObjectCollection localComputer = computer.GetInstances();
foreach(ManagementObject mo in localComputer)
{
localSystem = mo["Name"].ToString();
}
ManagementObjectCollection shares = exportedShares.GetInstances();
foreach(ManagementObject share in shares)
// dump UNC path
Console.WriteLine(@"UNC path \\{0}\{1}", localSystem, share["Name"]);
}

Willy.

Jan 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Glenn Venzke | last post by:
I have several folders on a test web server that are not visible in the directory structures of several programs, including Visual Interdev and Stac ReachOut. All these folders have one thing in...
1
by: Mystique | last post by:
Hello people! how can i get a list of all the folders that i are shared (shared for network) on my PC? Regards, Mystique
5
by: Dan Lorenz | last post by:
When trying to use the function CreateDirectory on my local machine everything works fine but when I upload the page to my webhost I get an issue that it can't find path on D:\, though D:\ is what...
0
by: Dennis | last post by:
I have tried to use the IWshRuntimeLibrary and ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk") to get all Logical Drives, Mapped Network Drives, Shared Folders and Shared Drives with...
1
by: lecnac | last post by:
Here's some details: Server and workstation both in the same workgroup Logged into server as local Administrator Logged into workstation as a local user that is only in the Users group The...
1
by: lecnac | last post by:
Sorry for the repost. I must have done something wrong when I tried to post my reply (I can't seem to find it). Anyway, I'd really appreciate any help that anyone could provide. My issue is...
0
by: NoWhereMan | last post by:
Hello, I'm trying to get the list of shared folders of a network computer and add them to a combo box. I'm using the bellow code in VB .NET. Code ==== Private Sub EnumShares(ByVal Machine As...
3
by: questionit | last post by:
Hi While accessing shared folder on the local network, it was possible to access the folder by just entering the workstation IP in windows explorer - and the shared folders will show up. From...
14
by: Betray | last post by:
We have a AD running on win2k3. We have many shared folders. Ive noticed that once in a while users will call up and report the folders missing. To fix the issue i would reboot the system. And vola...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.