1

I've a problem with an openFileDialog (default openFileDialog):

I've defined a filter (LogFiles|*.log) for my OpenFileDialog. Works fine, users can only select *.log file in a folder.

But, if these *.log files are in a zip archive, as the zip extension is natively recognized like a folder(CompressedFolder) by Windows and zip files displayed on the left Treeview of OpenFileDialog window, users are able to select the .*log files in the archive (and I don't want that!)

The filename returned par OpenFileDialog in this case is the filename of a temporary extracted file, so it seems not possible to test if the selected file is a zipEntry.

I only see 2 solutions to solve my problem:

1°) Accessing the registry, backup and removing the HKEY_CLASSES_ROOT.zip to restore it later (very bad solution!)

2°) As the OpenFileDialog is a sealed class, implement my own OpenFileDialog which prevent the display of *.log files inside a zip

Are there any other solutions?

Thanks.

mike3996
  • 17,047
  • 9
  • 64
  • 80
Jean-Luc
  • 29
  • 6
  • I don't see that the Open File Dialog search within zip files (at least not by default). – NoChance Jan 04 '14 at 10:40
  • OpenFileDialog don't search within zip file, but they're recognized as compressed folders, and so their content is diplayed and selectable – Jean-Luc Jan 04 '14 at 11:11
  • May be you can test the selected file using: http://stackoverflow.com/questions/11996299/c-net-identify-zip-file – NoChance Jan 04 '14 at 11:17
  • Can't testing the file, because after the selection, OpenFileDialog.FileNames returns the path of extracted file in the filename. I've found a solution with the OpenFileDialog.AutoUpgradeEnabled property set to false : with this setting, the left treeview of OpenFileDialog is disabled and there's no more way to display the content of an archive if its extension is no allowed by the filter :-) – Jean-Luc Jan 04 '14 at 11:25

1 Answers1

1

I've found a solution with the OpenFileDialog.AutoUpgradeEnabled property set to false.

With this setting, the left treeview of OpenFileDialog is not displayed (only shortcuts) and there's no more way to display the content of an archive if its extension is no allowed by the filter :-)

Jean-Luc
  • 29
  • 6
  • You know that a user can bypass the filter anytime by typing `*.*` into the filename textbox? – Andreas Adler Jan 04 '14 at 11:34
  • Yes, but it is not a problem... if user type `*.*` he can see the zip file in the folder, but he can't see the *.log inside the zip file. He can select the zip file (there's also a *.zip filter), in this case a specific treatment is done on this zip file – Jean-Luc Jan 04 '14 at 11:58
  • Oh, ok. Just read what the `AutoUpgradeEnabled` property does: It run's the `OpenFileDialog` in the legacy XP mode even on maschines that have Vista oder later. And since the Windows XP Explorer didn't had the feature to browse inside ZIP files it gives you the desired behavior. – Andreas Adler Jan 04 '14 at 12:08