Microsoft.Win32.SaveFileDialog 有效文件名问题

Microsoft.Win32.SaveFileDialog valid file name issue

运行 一个使用 .NET 4.5 的应用程序,用 C# 编写。当我调用 SaveFileDialog 时,我在文件名验证方面得到了混合结果。如果我输入一些常见的嫌疑人 {}<>/|等。我收到文件名无效的错误消息。这就是我所期望的。

但是,两个常见的嫌疑人特别引起了问题。如果我输入问号 (?) 或星号 (*),那么当我点击保存时什么也不会发生。不会发出有关无效字符的错误消息,并且对话框保持打开状态。我希望用户知道为什么什么都没发生,并告诉他们字符无效。我在网上找不到关于这是一个已知错误的任何信息。

有什么想法吗?我知道我可以将自己的事件添加到 FileOK,但它只会在构建后才执行,所以这对我没有好处,因为 FileOK 事件永远不会触发。

这是一项功能,自 Windows 3.1 以来,Windows 公用文件对话框就已包含此功能。它的作用是允许您使用文件名输入框以特定方式过滤当前目录的文件列表。 Raymond Chen 早在 2010 年就在他的博客中讨论过:

If you type a wildcard like ? or * into a common file dialog, the dialog interprets this as a request to filter the list of files to those which match the wildcard you specify. In this particular example, typing ?.jpg says "Show me all the single-character files with the .jpg extension." From the description in the original report, I gather that the customer's tests took place in an empty directory (so the filter had no effect).

我猜你也在一个空文件夹中测试过它,或者你会注意到在输入问号时文件列表被过滤了。