Click here to Skip to main content
15,509,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey all,

I'm using the standard File Open dialog box in my WinForms app, to prompt the user for a license file (extension ".lic") at startup if I don't find one in a predefined folder. My search filter is set to:

string strFilter = "License files (*.lic)|*.lic";

I've noticed a slight problem: If the folder happens to have, for example, "my.licensemanager.dll" in the selected folder, then because there's a ".lic" match as part of the *filename* (rather than extension), it gets included in the list of files being displayed - but being a DLL in this case, it obviously never will be a valid selection.

I would've thought a search for "*.lic" would NOT have picked up this file - only "*.lic*" would have picked it up, had this been the search criteria I would've used--but no, I'm using "*.lic". This is how "dir *.lic" at a command prompt behaves - the DLL is excluded unless I add the terminating "*".

I've been using the File Open dialog box for decades - pre-.NET, pre-MFC, going all the way back to the raw Win32 API in C even...and I hadn't noticed this until now.

I realize I can probably extend the File Open dialog in some fashion so I get full control over what gets included, but that (a) seems like overkill to me and (b) extending the File Open dialog always seems to carry with it some caveats or unintended quirk that's worse than the original problem I'm trying to solve.

Is there an alternate search pattern I might be able to use--a regex option perhaps that I've missed, instead of plain-text? I don't recall ever seen this in the documentation.

What I have tried:

Not many alternatives to try - I'm following the documentation to the letter and it seems to me like a bad implementation.
Posted
Updated 25-Feb-18 7:56am

When I try that:
C#
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "License files (*.lic)|*.lic";
if (ofd.ShowDialog() == DialogResult.OK)
    {
    string path = ofd.FileName;
    }
With just two files in the folder "dimchain.lic" and "DMLog.licence.txt" i can see the first, but not the second in the files list. If I type 'd' I can see - and select - both files in the pop-out list, but I cannot see "DMLog.licence.txt" in teh files list at all.

What am I doing differently from you?
 
Share this answer
 
Good question. I've seen this on clean Windows 8 and 8.1 VMs. In both instances, Windows Explorer is set to show everything (don't hide anything at all--ever).
 
Share this answer
 
Comments
Richard Deeming 26-Feb-18 10:39am    
If you want to reply to a solution, click the "Have a Question or Comment?" button under that solution.

DO NOT post your reply as a new "solution".
dandy72 26-Feb-18 12:31pm    
Thanks. I *had* been looking for that, but when there's a single response, it's not obvious the button is a follow-up for *that*. It's more obvious once there's more than one solution posted, and there's one such button for each.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900