简体   繁体   English

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

[英]Microsoft.Win32.SaveFileDialog valid file name issue

Running an application with .NET 4.5, written in C#. 使用C#编写的.NET 4.5运行应用程序。 When I call a SaveFileDialog I get mixed results on the validation of file names. 当我调用SaveFileDialog时,在验证文件名时会得到不同的结果。 If I input some of the usual suspects {}<>/| 如果我输入一些常见的嫌疑人{} <> / | etc. I get an error that the file name is not valid. 等等。我收到文件名无效的错误消息。 That's what I would expect. 那就是我所期望的。

However, two of the usual suspects in particular cause an issue. 但是,通常有两个嫌疑人引起了问题。 If I enter a question mark (?) or an asterisk (*) then when I hit Save nothing happens. 如果我输入一个问号(?)或一个星号(*),则当我单击“保存”时,什么也不会发生。 No error message is issued about the invalid characters, and the dialog just stays open. 不会发出有关无效字符的错误消息,并且对话框保持打开状态。 I'd like the user to know why nothing happened and tell them the characters are invalid. 我想让用户知道为什么什么也没发生,并告诉他们字符无效。 I can't find anything online about this being a known bug. 我找不到任何有关此已知错误的在线信息。

Any ideas? 有任何想法吗? I know I can add my own event to FileOK but it only gets executed AFTER the build in one, so that does me no good because the FileOK event never fires. 我知道我可以将自己的事件添加到FileOK中,但是它仅在构建一次后才执行,所以这对我没有好处,因为FileOK事件永远不会触发。

This is a feature, one that's been with the Windows Common File Dialogs since Windows 3.1. 这是一项功能,自Windows 3.1以来,Windows通用文件对话框一直在使用该功能。 What it does is allow you to filter the current directory's file list in an ad-hoc manner using the filename input box. 它的作用是允许您使用文件名输入框以临时方式过滤当前目录的文件列表。 Raymond Chen discussed it in his blog as far back as 2010: 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." 在此特定示例中,键入?.jpg表示“向我显示所有扩展名为.jpg的单字符文件”。 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). 从原始报告的描述中,我收集到客户的测试是在一个空目录中进行的(因此过滤器无效)。

I'm guessing you tested it in an empty folder as well, or you would have noticed the file list getting filtered when the question mark was typed. 我猜您也在一个空文件夹中进行了测试,或者您会注意到在键入问号时文件列表已被过滤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM