【发布时间】:2014-10-30 00:45:24
【问题描述】:
我正在使用 VS2013 Express for Desktop 并使用 Windows 窗体。
我关注this MSDN Walkthrough "Creating an Explorer Style Interface with the ListView and TreeView Controls Using the Designer"。所以我试图让树视图从“MyComputer”级别开始,以便用户可以选择所有驱动器号。
适用于 MyDocuments,如下:
DirectoryInfo info = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
但是当我从自动完成中选择 MyComputer 时它不起作用:
DirectoryInfo info = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyComputer));
我明白了:
在 mscorlib.dll 中出现“System.ArgumentException”类型的未处理异常 附加信息:路径不是合法形式。
这令人惊讶,因为“MyComputer”在自动完成功能中可用,但不像其他特殊文件夹那样工作。
谢谢。
更新: 谢谢 ByteBlast 和 CodyGray。
在这里问我应该怎么做是否合适?
【问题讨论】:
-
这是学习如何使用调试器的好时机。创建一个额外的变量并将 Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) 的结果放入其中。然后使用调试器检查返回的内容。
-
@gus:我也遇到了同样的问题。您找到任何解决方案或替代方案了吗?
标签: c# windows winforms visual-studio special-folders