从打开文件对话框在C#中不包括的文件扩展名 [英] Excluding file extensions from open file dialog in C#

查看:169
本文介绍了从打开文件对话框在C#中不包括的文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把一个过滤器上排除某些文件扩展我的C#的OpenFileDialog。例如,我想让它显示在未名为.txt文件的目录中的所有文件。

I am trying to put a filter on my C# openFileDialog that excludes certain file extensions. For example I want it to show all files in a directory that are not .txt files.

有没有办法做到这一点?

Is there a way to do this?

推荐答案

有就是做这个用的BCL的OpenFileDialog没有直接的方法。

There is no direct way to do this using the BCL OpenFileDialog.

我能想到的几个选项:

1)制作,仅仅拥有所有你想要支持的类型的过滤器。这将是我的建议,因为这是要去有关此类操作的最常见方式。

1) Make a filter that just has all of the types you do want to support. This would be my recommendation, since that's the most common way of going about this type of operation.

2)使用沿着这个东西线的自定义打开文件对话框实现。然后,您可以覆盖OnFileNameChanged()方法可能禁用打开按钮,如果所选文件的扩展名为.txt。

2) Use something along the lines of this custom OpenFileDialog implementation. You could then override the OnFileNameChanged() method to potentially disable the "Open" button if the selected file has a .txt extension.

3)让用户选择一个。 txt文件,扔了一个错误对话框,并重新打开文件对话框。这种感觉笨重,不太大我,虽然....

3) Let the user pick a .txt file, throw up an error dialog, and reopen the file dialog. This feels clunky and not too great to me, though....

这篇关于从打开文件对话框在C#中不包括的文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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