C# Prevent OpenFileDialog to display ZipEntries of a Zip file

时间秒杀一切 提交于 2020-01-05 04:18:14

问题


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.


回答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 :-)



来源:https://stackoverflow.com/questions/20919773/c-sharp-prevent-openfiledialog-to-display-zipentries-of-a-zip-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!