Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access a mapped network drive with System.IO.DirectoryInfo?

Tags:

c#

.net

People also ask

How do I access a mapped drive?

Open File Explorer from the taskbar or the Start menu, or press the Windows logo key + E. Select This PC from the left pane. Then, on the File Explorer ribbon, select More > Map network drive.

How do I access a network drive outside of network?

How to access network drive from outside network? Using a VPN is the best way to access a network drive. Accessing a mapped network drive from outside your network can be done by typing the IP address of the remote computer in the search bar.

How do I connect to a network Map?

Click File Explorer.Click This PC in the left side shortcut menu. Click Computer > Map network drive > Map network drive to enter Mapping wizard. Confirm drive letter to use (next available shows up by default).


Mapped network drives are user specific, so if the app is running under a different identity than the user that created the mapped drive letter (z:) it won't work.


Based on the fact, mapped drive letters don't work, the simple solution is to type the full network path.

Aka,

my R:/ drive was mapped to \\myserver\files\myapp\

So instead of using

"R:/" + "photos"

use

"\\myserver\files\myapp\" + "photos"


The account your application is running under probably does not have access to the mapped drive. If this is a web application, that would definitely be the problem...By default a web app runs under the NETWORK SERVICE account which would not have any mapped drives setup. Try using impersonation to see if it fixes the problem. Although you probably need to figure out a better solution then just using impersonation. If it were me, I'd stick to using the UNC path.


Are you mapping with the exact same credentials as the program is running with?


Are you running on Vista/Server 2k8? Both of those isolate services into Session 0 and the first interactive session is Session 1. There's more info here, on session isolation. Thus, even if it's the same user being used for both the service and the interactive logon, it'll be different sessions.


You can try to use WNetConnection to resolve the mapped drive to a network path.