我如何可以访问System.IO.DirectoryInfo映射网络驱动器? [英] How can I access a mapped network drive with System.IO.DirectoryInfo?

查看:728
本文介绍了我如何可以访问System.IO.DirectoryInfo映射网络驱动器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在映射的网络驱动器上创建一个目录。我使用的是code:

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

DirectoryInfo targetDirectory = new DirectoryInfo(path);
if (targetDirectory != null)
{
    targetDirectory.Create();
}

如果我指定一个像\\\\服务器名\\目录的路径,这一切都OK。如果我映射\\服务器\目录的,说的驱动器Z :,并指定类的路径。Z:\\,它失败

If I specify the path like "\\\\ServerName\\Directory", it all goes OK. If I map the "\\ServerName\Directory" as, say drive Z:, and specify the path like "Z:\\", it fails.

在创建targetDirectory对象,VS显示(在调试模式)targetDirectory.Exists =假,并尝试做targetDirectory.Create()抛出一个异常后:

After the creating the targetDirectory object, VS shows (in the debug mode) that targetDirectory.Exists = false, and trying to do targetDirectory.Create() throws an exception:

System.IO.DirectoryNotFoundException: "Could not find a part of the path 'Z:\'."

然而,同样的code能够很好地处理本地目录,例如: C:

However, the same code works well with local directories, e.g. C:.

该应用程序是一个Windows服务(专业版的WinXP,SP2,.NET 2)根据相同的帐户作为映射驱动器的用户身份运行。 Qwinsta回复用户的会话是会话0,所以它是同届会议上作为服务的。

The application is a Windows service (WinXP Pro, SP2, .NET 2) running under the same account as the user that mapped the drive. Qwinsta replies that the user's session is the session 0, so it is the same session as the service's.

推荐答案

映射网络驱动器是用户特定的,所以如果应用程序是在比创建的映射驱动器号(用户不同的身份运行z :)它赢得了科技工作。

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.

这篇关于我如何可以访问System.IO.DirectoryInfo映射网络驱动器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆