网络路径上的Directory.CreateDirectory [英] Directory.CreateDirectory on a network path
问题描述
我正在尝试在网络路径上创建一个新的目录树.
I'm trying to create a new directory tree on a network path.
该共享位于\\192.168.5.193\FileContext
上,并具有Everyone
完全访问权限权限.
The share is located at \\192.168.5.193\FileContext
and has Everyone
full access permissions.
这段代码:
DirectoryInfo directoryInfo = Directory.
CreateDirectory(@"\\192.168.5.193\FileContext\FileContext_Root\General\Test");
给我:
An exception of type 'System.IO.IOException' occurred in mscorlib.dll
but was not handled in user code
Additional information: Logon failure: unknown user name or bad password.
如果我尝试使用Windows资源管理器打开相同的地址,则无需密码即可打开它.
If I try to open the same address with Windows Explorer, it opens up without password requirements.
CreateDirectory()
文档指出它应接受UNC路径:
The CreateDirectory()
documentation states it should accept UNC paths:
您可以在具有写访问权限的共享上的远程计算机上创建目录.支持UNC路径;例如,可以为路径指定以下内容:在Visual Basic中为\ 2009 \ Archives \ December,在C#中为\\ 2009 \ Archives \ December.
You can create a directory on a remote computer, on a share that you have write access to. UNC paths are supported; for example, you can specify the following for path: \2009\Archives\December in Visual Basic, and \\2009\Archives\December in C#.
它还指出,IOException
可能来自:
path指定的目录是文件.
-或-
网络名称未知.
The directory specified by path is a file .
-or-
The network name is not known.
https://msdn. microsoft.com/en-us/library/vstudio/54a0at6s(v=vs.100).aspx
我该如何解决?
推荐答案
从@JamesThorpe评论开始:
Starting from @JamesThorpe comment:
我通过将远程计算机添加到公司域来解决该问题.
I came to the solution, just by adding the remote computer to the company domain.
通过此操作,甚至不必将本地计算机的NETWORK SERVICE
添加到远程文件夹的权限中.
With this action, it's not even necessary to add local computer's NETWORK SERVICE
to remote folder's permissions.
这篇关于网络路径上的Directory.CreateDirectory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!