我如何可以访问System.IO.DirectoryInfo映射网络驱动器?驱动器、网络、System、IO

由网友(霸气带点狠)分享简介:我需要在映射的网络驱动器上创建一个目录。我使用的是code:I need to create a directory on a mapped network drive. I am using a code:DirectoryInfo targetDirectory = new DirectoryInfo(path...

我需要在映射的网络驱动器上创建一个目录。我使用的是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 "\ServerNameDirectory", it all goes OK. If I map the "ServerNameDirectory" 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.

阅读全文

相关推荐

最新文章