我需要在映射的网络驱动器上创建一个目录。我正在使用以下代码:
DirectoryInfo targetDirectory = new DirectoryInfo(path);
if (targetDirectory != null)
{
targetDirectory.Create();
}
如果我指定路径为“\\\\ServerName\\Directory”,一切都正常。 如果我将“\\ServerName\Directory”映射为Z:驱动器,并指定路径为“Z:\\”,则会失败。
在创建targetDirectory对象后,VS(调试模式)显示targetDirectory.Exists = false,尝试执行targetDirectory.Create()会引发异常:
System.IO.DirectoryNotFoundException: "Could not find a part of the path 'Z:\'."
然而,相同的代码在本地目录(例如C:)中运行良好。
该应用程序是一个Windows服务(WinXP Pro,SP2,.NET 2),在映射驱动器的用户帐户下运行。 Qwinsta回复说用户的会话是会话0,因此与服务的会话相同。