当 RootFolder 是 MyComputer 时,为什么 FolderBrowserDialog 不允许桌面作为 SelectedPath? [英] Why does FolderBrowserDialog not allow the desktop as SelectedPath when RootFolder is MyComputer?

查看:34
本文介绍了当 RootFolder 是 MyComputer 时,为什么 FolderBrowserDialog 不允许桌面作为 SelectedPath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有效:

FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.RootFolder = Environment.SpecialFolder.MyComputer;
dlg.SelectedPath = "C:\\Almo\\";
dlg.ShowDialog();

这不会:

FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.RootFolder = Environment.SpecialFolder.MyComputer;
dlg.SelectedPath = "C:\\Users\\Almo\\Desktop\\";
dlg.ShowDialog();

第一个从 C:\Almo 开始打开文件选择对话框,第二个从 MyComputer 开始.有没有办法使这项工作?问题是我的应用程序的默认保存位置是桌面,我希望用户能够选择不同的位置,并且我希望对话框从当前位置开始.

The first opens a fileselection dialog starting in C:\Almo, the second started at MyComputer. Is there a way to make this work? The issue is my Application's default save location is the Desktop, and I want the user to be able to select a different location, and I want the dialog to start wherever the current location is.

推荐答案

显然,Win 7 中的桌面实际上并不存在于路径上

Apparently, the Desktop in Win 7 doesn't actually exist at the path

c:\用户\用户名\桌面

c:\Users\username\Desktop

系统假装它在命令提示符和 Windows 资源管理器中执行.但由于它不存在,SelectedPath 中要求其路径位于 RootFolder 下的部分不允许以这种方式设置路径.

The system pretends it does at the command prompt and in windows explorer. But since it isn't there, the part of SelectedPath that requires its path to be under RootFolder disallows setting the path in that way.

这篇关于当 RootFolder 是 MyComputer 时,为什么 FolderBrowserDialog 不允许桌面作为 SelectedPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆