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

How to get a list of all shared folders?

P: n/a
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
Share this Question
Share on Google+
3 Replies


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

P: n/a

"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.