c# - var di = new DirectoryInfo(path) 抛出异常,直到我第一次使用 Windows 资源管理器打开路径

标签 c# directoryinfo

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/

相关文章:

c# - Asp.Net MVC 2 中的 AccountController 将其数据存储在哪里?

c# - 在反序列化过程中有选择地转义字符串中的 HTML

c# - “目标帐户名称不正确”-DirectoryInfo.GetFiles 出现 IOException

c# - 如何获取正则表达式匹配字符串的文件路径?

c# - 获取目录信息对象的路径

c# - 在 WCF 启动时运行函数

c# - 在 MVC 中向我的编辑 Controller 添加删除功能

c# - LINQ 从两个具有相同长度的集合中选择

c# - 查找文件文件夹的最新最后修改时间的最佳方法是什么?

c# - 如果 DirectoryInfo 包含目录