.NET 中有 OpenFileOrFolderDialog 对象吗?
是否可以使用 OpenFileDialog
类选择文件或文件夹? 它似乎只允许选择文件,如果您选择一个文件夹然后选择打开它将导航到该文件夹。
如果 OpenFileDialog
不能用于此目的,是否还有我应该使用的另一个对象?
编辑:情况是我有一个可以上传一个...多个文件或文件夹的工具。 我需要能够提供一个像 OpenFileDialog
这样的对话框,允许用户选择文件、文件夹或其组合。 我知道 FolderBrowseDialog
这不是本例的答案。
Is it possible to use the OpenFileDialog
class select a file OR folder? It appears only to allow the selection of a file, if you select a folder and then choose open it will navigate to that folder.
If the OpenFileDialog
can not be used for this is there another object I should be using?
EDIT: The scenario is that I have a tool that can upload one...many files or folders. I need to be able to provide a dialog like the OpenFileDialog
that allows a user to select a file, folder, or a combination of. I know about the FolderBrowseDialog
and that is not the answer in this case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是我一直在寻找的解决方案,本文提供了代码并描述了如何创建满足我的需求的对话框。
CodeProject:IShellBrowser 的完整实现
This is the solution I have been looking for, this article provides code and describes how to create a dialog that meets my needs.
CodeProject: Full Implementation of IShellBrowser
是的,您可以使用 OpenFileDialog 选择文件夹。 这是 CodeProject 中的一篇文章,演示了一种实现此操作的方法 (http://www. codeproject.com/KB/dialog/OpenFileOrFolderDialog.aspx)。
Yes, you can use OpenFileDialog to select a folder. Here is an article in CodeProject that demonstrated a way to do it (http://www.codeproject.com/KB/dialog/OpenFileOrFolderDialog.aspx).
根据我在 .NET 的经验,我不得不说不,对于否定和简短的回答感到抱歉,但我真的不认为有
In my experience in .NET, I would have to say no, sorry for the negative and short answer, but I really don't think there is
如果您有时间,您可以使用 System.Windows.Forms.TreeView 类。 每个节点都可以有一个复选框,因此如果您填充树视图(onexpand),您可以让用户选择他想要上传的文件/目录。
这应该让您开始使用目录填充树视图,在树视图中添加文件的工作应该不那么难:
http://www.java2s.com/Tutorial/VB/0280__GUI-Applications/FileTreeview.htm
If you have time, you can create your own pretty easily by using the System.Windows.Forms.TreeView Class. Each node can have a checkbox, so If you populate the treeview (onexpand) you can let the user select the files/directories he wants to upload.
This should get you started on populating the treeview with directories, the job to also add files in the treeview should not be that hard:
http://www.java2s.com/Tutorial/VB/0280__GUI-Applications/FileTreeview.htm
否:OpenFileDialog 仅用于打开文件。 无论如何,您可以使用一个FolderBrowserDialog。
[编辑]回答太快:提问者的编辑是在之后。
No: the OpenFileDialog is just for opening files. Anyway there is a FolderBrowserDialog you can use for that.
[Edit] Answered too fast: the Edit from the questioner was afterwards.
我建议看一下 Ookii Dialogs 库,它有一个分别为 Windows 窗体和 WPF 实现文件夹浏览器对话框:
I'd suggest taking a look at the Ookii Dialogs libraries which have an implementation of a folder browser dialog for Windows Forms and WPF respectively: