var di = new DirectoryInfo(Root);
var diList = di.GetDirectories();
访问位于网络上的文本路径“Root”时,上述崩溃。 I 仅在用户首次登录 Windows 7 时发生(未在其他操作系统上进行测试)。如果用户使用 Windows 资源管理器导航到指定路径,则 di 能够检索目录。
我知道可以进行捕获并提示用户单击打开 Windows 资源管理器并导航到路径的链接,但我不适合解决此问题。我希望我的程序能够建立与网络路径的连接,而不需要 Windows 资源管理器先执行此操作。
异常(exception):
System.IO.IOException: The network name cannot be found.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator`1.CommonInit()
at System.IO.FileSystemEnumerableIterator`1..ctor(String path,string originalUserPath,
String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler,
Boolean checkHost)
at System.IO.DirectoryInfo.InternalGetDirectories(String searchPattern,
SearchOption searchOption) at Controls.ValidationControl.LoadDBox(Object sender,
RoutedEventArgs e)
in c:\Controls\ValidationControl.xaml.cs:line 1010
预先感谢您的支持, 约翰
最佳答案
Microsoft 的安全措施将阻止您使用应用程序捕获的凭据通过 UNC 访问 SharePoint。因此,在尝试了上述所有解决方案和其他 3 个网络访问类之后,没有人会看到路径并让我登录,所以我只是使用了
Process.Start(dir);
并提示用户发生了什么事。 Windows 资源管理器将使用用户的凭据启动,并导航到 Windows 然后使用用户的域帐户登录 SharePoint 的路径。 Windows 可以做到。不为 Microsoft 工作的程序员就不能。
关于c# - var di = new DirectoryInfo(path) 抛出异常,直到我第一次使用 Windows 资源管理器打开路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17583010/