C#防止OpenFileDialog显示Zip文件的ZipEntries [英] C# Prevent OpenFileDialog to display ZipEntries of a Zip file

查看:148
本文介绍了C#防止OpenFileDialog显示Zip文件的ZipEntries的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用openFileDialog(默认的openFileDialog)时遇到问题:

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

我已经为我的OpenFileDialog定义了一个过滤器(LogFiles|*.log).工作正常,用户只能选择文件夹中的* .log文件.

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

但是,如果这些* .log文件位于zip归档文件中,则因为Windows本身就知道该zip扩展名像文件夹(CompressedFolder)一样,并且zip文件显示在OpenFileDialog窗口的左侧Treeview中,所以用户可以选择.* log文件中的档案(我不想要!)

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

在这种情况下,通过OpenFileDialog返回的文件名是临时提取的文件的文件名,因此似乎无法测试所选文件是否为zipEntry.

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.

我只看到2种解决方案来解决我的问题:

I only see 2 solutions to solve my problem:

1°)访问注册表,备份并删除HKEY_CLASSES_ROOT.zip以稍后恢复(非常糟糕的解决方案!)

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

2°)由于OpenFileDialog是一个密封的类,请实现我自己的OpenFileDialog,以防止在zip文件中显示* .log文件

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

还有其他解决方案吗?

谢谢.

推荐答案

我发现OpenFileDialog.AutoUpgradeEnabled属性设置为false的解决方案.

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

使用此设置,将不显示OpenFileDialog的左树视图(仅显示快捷方式),并且如果过滤器不允许扩展名,则没有更多方法显示存档的内容:-)

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

这篇关于C#防止OpenFileDialog显示Zip文件的ZipEntries的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆