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

后端 未结 7 1690
无人及你
无人及你 2020-12-28 13:03

I need to create a directory on a mapped network drive. I am using a code:

DirectoryInfo targetDirectory = new DirectoryInfo(path);
if (targetDirectory != nu         


        
相关标签:
7条回答
  • 2020-12-28 13:28

    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.

    0 讨论(0)
  • 2020-12-28 13:38

    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"

    0 讨论(0)
  • 2020-12-28 13:38

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

    0 讨论(0)
  • 2020-12-28 13:42

    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.

    0 讨论(0)
  • 2020-12-28 13:45

    I had the same problem on Win Server 2012. The disabling UAC solved it.

    0 讨论(0)
  • 2020-12-28 13:46

    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.

    0 讨论(0)
提交回复
热议问题