我正在使用VS2013 Express for Desktop和Windows Forms。

我正在关注this MSDN Walkthrough "Creating an Explorer Style Interface with the ListView and TreeView Controls Using the Designer"。因此,我试图使树 View 从“MyComputer”级别开始,以便所有驱动器号可供用户选择。

它适用于MyDocuments,如下所示:

DirectoryInfo info = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));

但是当我从自动完成中选择MyComputer时,它不起作用:
DirectoryInfo info = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyComputer));

我得到:



令人惊讶的是,“MyComputer”在自动完成功能中可用,但不能像其他特殊文件夹一样工作。

谢谢你。

更新:
谢谢ByteBlast和CodyGray。

在这里问我应该怎么做呢?

最佳答案

The documentation指出:



DirectoryInfo构造函数提供空字符串是导致ArgumentException的原因。

Elsewhere on MSDN您可以找到有关为什么返回空字符串的解释:

09-26 20:08