.Net provides us with a FolderBrowserDialog control to browse for folders. This is however a modal dialog box. I need to create a user control that I can drop onto my form. So, I have been looking at creating my own, where I need to get all local drives, mapped network drives, UNC shares and web folders (WebDAV/SharePoint). I am using Windows 7 and .Net 4.0.
Local and Mapped Network Drives
I can get the local drives from DriveInfo.GetDrives(). However, these are only showing me the drives that are available/online. In Windows Explorer, you also see mapped network drives that are disconnected/unavailable.
Network Folders/UNC Shares
From what I have found so far, there does not appear to be a mechanism in .Net to enumerate the UNC shares. It seems that I have to use Interop to Win32 APIs to use the WNetOpenEnum
and WNetEnumResource
functions to enumerate the network neighborhood. I got this working, but was wondering if there was not another way.
Web (WebDAV) Folders and SharePoint
In Windows Explorer I configured a few WebDAV folders. Using the same Interop calls above WNetOpenENum
and WNetENumResource
I got a node "Web Client Network" and the WebDAV folders that were connected and accessible appeared.
Questions
- How do I get the mapped network drives that are configured, but are offline?
- Is there another way to enumerate UNC shares, or am I stuck with using the above named interop calls?
- The
WNetEnumResource
was returning to me an empty node for "Microsoft Terminal Services". How can I filter this out, without filtering based on the English text? - The web folders returned by
WNetEnumResource
are not the user friendly names I assigned to them when I created them, but are in the format of IP-Address@Port, e.g.\\nnn.nnn.nnn.nnn@18123
. How do I get the user friendly names for the web folders? - The web folders that were offline, did not appear at all, yet in Windows Explorer these are appearing. Any suggestions on getting the ones that are offline?
yes you can do this take a look at this site and it will show you how to do it in VB as well as C#
Enumerating Network Drives / Shares
here is a sample app you can try as well from codeproject