简体   繁体   中英

Microsoft.Win32.SaveFileDialog valid file name issue

Running an application with .NET 4.5, written in C#. When I call a SaveFileDialog I get mixed results on the validation of file names. 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.

This is a feature, one that's been with the Windows Common File Dialogs since Windows 3.1. 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:

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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