开发者

C# .Net 4 Retrieve shared folders

开发者 https://www.devze.com 2023-01-21 06:40 出处:网络
I\'m creating a WPF file explorer treeview (in C# 4) and I need it to work with UNC. For example, lets say I have these shared networks folders:

I'm creating a WPF file explorer treeview (in C# 4) and I need it to work with UNC. For example, lets say I have these shared networks folders:

\\share\test1
\\share\tes开发者_运维问答t2
\\share\test3
\\share\test4

If I only have \\share, how can I determine what shared folders are within that path? \share is not a shared folder in and of itself.


Take a look at http://www.codeproject.com/KB/IP/networkshares.aspx. This contains an explanation with working source code.


use WMI as bellow:

using (System.Management.ManagementClass shareObj = new
System.Management.ManagementClass("Win32_Share"))
{
  System.Management.ManagementObjectCollection shares =
  shareObj.GetInstances();

  foreach (System.Management.ManagementObject share in shares)
  {
    Console.WriteLine("Name: " + share["Name"].ToString());
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消