C# – Check if directory exists on Network Drive

.net-4.0cvb.netwindows

I'm trying to detect if the directory exists, but in this particular situation my directory is a network location.
I used VB.NET's My.Computer.FileSystem.DirectoryExists(PATH) and the more general System.IO.Directory.Exists(PATH), and in both cases, the system response is false.
I checked and the PATH exists, I can view it in MyComputer Folder.
If I debug the program, and watch the My.Computer.FileSystem.Drives variable, the network location does not appear in that list.

UPDATE: I checked and in Windows XP the Response is True, but not in Windows 7.

UPDATE2: I tested both proposed solutions but I still have the same problem, on the image below you will see that I can access using Explorer but my program cannot.
The GetUNCPath function returns a valid path (no errors), but Directory.Exists stil returns false.

I also tried with the UNC path "\\Server\Images"; same result.

enter image description here

UPDATE3: If I cannot link with a network drive, how can I link to UNC path directly?. I discovered that if i run VS in normal mode, it works, but my software must run in administrator mode. So, there is any way to check the existence of a network directory as administrator?

Best Answer

If UAC is turned on, mapped network drives only exist "by default" in the session they are mapped: Normal or elevated. If you map a network drive from explorer, then run VS as admin, the drive will not be there.

You need to enable what MS calls "linked connections": HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System: EnableLinkedConnections (REG_DWORD) = 0x1

Background Information about "two logon sessions" with UAC: http://support.microsoft.com/kb/937624/en-us