是否根据内容过滤OpenFileDialog中显示的文件? [英] Filtering the files shown in OpenFileDialog based on content?

查看:77
本文介绍了是否根据内容过滤OpenFileDialog中显示的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以修改OpenFileDialog的行为,使其在打开的文件夹中查看文件,然后根据其内容忽略某些文件?

Is there a way to modify the behavior of the OpenFileDialog so that it looks inside the files in the folder it opens to and then ignores certain ones based on their content?

一个示例是打开一个包含Zip文件的文件夹,但仅显示包含特定文件的文件夹.

One example would be to open to a folder full of Zip files but only show the ones that contain a certain file.

从文档中可以看到HookProc,但我不确定如何使用它.

From the documentation, there's the HookProc but I'm not exactly sure how I'd use it.

请注意,如果有可能,我意识到这将是一个相对较慢的操作.目前,我不关心性能.

Please note that if it is possible, I realize that it'll be a relatively slow operation. At the moment I'm not concerned about performance.

谢谢!

推荐答案

我不会忽略OpenFileDialog的复杂性.构建真正可行的工具并非易事.当您构建自己的对话框时,它不是普通"对话框,因此会混淆用户.即使做得很好,这也是对的,这是困难的.因此,我建议您坚持扩展已有的内容,而不是编写新的内容.

I wouldn't dismiss the complexity of the OpenFileDialog. It's not so easy to build one that really works. When you do build your own, it's not the "normal" dialog and as a result it confuses users. This is true even if you do it well, which is difficult. So I'd suggest you stick to extending what is already there, rather than writing something new.

本文中查找可能/可能是OFD的扩展调整以精确地做您想要的.您使用C#编写了一个响应路径选择的回调.

Check this article for an extension of OFD that might/could be tweaked to do exactly what you want. There's a callback that you write in C# that responds to path selection.

相关: FolderBrowserDialogEx 是FolderBrowserDialog上的类似扩展名.尽管有名称,您可以对其进行配置以搜索文件以及文件夹.有选择的东西(文件夹,文件)时被调用的回调,而回调中,你可以做你需要做什么.例如,在文件夹内的文件内偷看,并填充文件列表以仅显示那些文件.

Related: FolderBrowserDialogEx is a similar extension on FolderBrowserDialog. Despite the name, you can configure it to search for files, as well as folders. There's a callback that gets invoked when something (a folder, a file) is selected, and within that callback you can do what you need to do. For example, peek inside the files within a folder and populate the list of files to display with only those files.

您可能会考虑的另一种选择是来自Ookii的对话框库.这是OpenFileDialog的开源实现,它包括Vista中所有新对话框内容的COM包装.使用该库,您可以弹出Vista OpenFileDialog并从 IFileDialogEvents 接口,使用C#代码.这样的事件之一就是OnFolderChange().在处理程序中,您可以调用IFolder.GetFolder(),这将为您提供

Another option you might consider is the dialog library from Ookii. This is an open source implementation of the OpenFileDialog, and it includes COM wrappers for all the new dialog stuff in Vista. Using that library you can pop a Vista OpenFileDialog and receive events from the IFileDialogEvents interface, in C# code. One such event is OnFolderChange(). Within the handler you could call IFolder.GetFolder() which will get you an IShellItem, which gives you the folder the user is changing to. The next step would be to itemize and potentially filter the set of files, which is an exercise I will leave to the reader...

这篇关于是否根据内容过滤OpenFileDialog中显示的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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