打开文件对话框 - 仅显示没有扩展名的文件名 [英] OpenFileDialog - only display filenames that have no extensions

查看:175
本文介绍了打开文件对话框 - 仅显示没有扩展名的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码在我的C#程序:

I have the following code in my C# program:

        OpenFileDialog fDialog = new OpenFileDialog();
        fDialog.Title = "Open a file";
        fDialog.Filter =
           "NCF files (*.ncf)|*.ncf|All files (*.*)|*.*|No Extensions (*.)|*.";






我希望能够让用户从以下挑选:



.NCF

(与.NCF只有扩展文件)< 。b>
的* (所有文件)



I want to be able to have the user pick from the following:

.NCF (files with .NCF extension only)
*.* (all files)

和文件具有的没有扩展如:


filewithnoextension





我知道的 * 。*会这么做,但它也显示了.NCF,.TXT,并在同一目录中的所有其他文件。

我只是想能够显示没有扩展名的文件名。





过滤带*号。不会做的伎俩。用DOS窗口时在做它工作正常( DIR *。),但C#似乎忽视了*。过滤器。

and files that have no extensions such as:

filewithnoextension



I know *.* will do this, but it also displays the .NCF, .TXT, and all other files in the same directory.

I just want to be able to display filenames that have no extensions.



Filtering with *. does not do the trick. It works fine when doing it with a DOS window (dir *.) , but C# seems to ignore the *. filter.






是有办法,我可以用C#这样做吗?





Is there a way I can do this with C#?

感谢。

推荐答案

如果其他软件程序在这些文件同一地点,为什么没有你的代码添加扩展名(无伤大雅的东西,如.XXX),该文件夹中的每一个扩展名的文件和然后的显示对话框?

If the other software program creates these files in the same location, why not have your code add an extension (something innocuous like ".XXX") to every extension-less file in that folder, and then show the dialog?

修改或,看到这个MSDN文章:

Or, see this MSDN article:

http://msdn.microsoft.com/en-us/library/ms646960(VS.85)的.aspx

过滤器部分:

的CDN_INCLUDEITEM通知
消息提供另一种方式来过滤
,对话框
显示的名称。要使用这个邮件,提供
的OFNHookProc钩子程序和
在创建对话框中指定的OPENFILENAME结构
的OFN_ENABLEINCLUDENOTIFY
标志。每个
时间的用户打开文件夹时,
对话框发送CDN_INCLUDEITEM
通知你的钩子程序
。在新开的
文件夹中的每个项目。钩
过程的返回值表示对话框
框是否应显示在
文件夹的项目列表中的项目。

The CDN_INCLUDEITEM notification message provides another way to filter the names that the dialog box displays. To use this message, provide an OFNHookProc hook procedure and specify the OFN_ENABLEINCLUDENOTIFY flag in the OPENFILENAME structure when you create the dialog box. Each time the user opens a folder, the dialog box sends a CDN_INCLUDEITEM notification to your hook procedure for each item in the newly opened folder. The return value of the hook procedure indicates whether the dialog box should display the item in the folder's item list.

下来在浏览器风格的钩子程序底部部分,文章介绍了如何做到这一点。基本上,你传递一个事件处理程序打开文件对话框,每一次用户导航到一个新的文件夹,在文件夹中的所有文件的对话框进行迭代,并且要求每一个事件处理程序。在事件处理器中,你会把你的代码,以确定是否该文件有一个扩展与否,并返回true或false,相应地。

Down at the bottom in the Explorer-Style Hook Procedures section, the article explains how to do this. Basically, you pass an event handler to the OpenFile dialog, and each time the user navigates to a new folder, the dialog iterates through all the files in the folder and calls your event handler for each one. Inside the event handler, you would put your code to determine if the file has an extension or not, and return true or false, accordingly.

这篇关于打开文件对话框 - 仅显示没有扩展名的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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