【发布时间】:2012-01-04 21:26:13
【问题描述】:
当使用System.IO.Packaging 程序集读取压缩包时,我发现无法读取使用标准 windows zip 实用程序创建的压缩文件(压缩包的包部分(内部文件)显示为不存在) .
经过一些研究,这似乎是因为System.IO.Packaging 库在创建 zip 时将 Content_Types.xml 添加到 zip 中,这似乎不存在于标准 Windows 压缩文件中压缩包。
例子:
using (Package Zip = Package.Open(BundlePath, FileMode.Open))
{
Uri FileUri = PackUriHelper.CreatePartUri(new Uri("somefile.xml", UriKind.Relative));
if (!Zip.PartExists (FileUri )) //this fails even though the file exists in the zip
throw new ResourceException(String.Format("Zip {0} does not contain file", BundlePath));
...
是否仍然使用 .NET 提供的打包系统来读取标准 zip 文件,还是需要使用库创建。
编辑:
手动添加此文件 (Content_Types.xml),并使用 Windows 压缩实用程序进行压缩,证明成功地允许读取包。
谢谢。
【问题讨论】:
-
什么是“标准 windows zip 实用程序”?
-
@Oded - Windows XP、Windows 7 等系统自带的默认压缩工具
-
我会再问一次,因为我不知道 XP 自带的。
-
@Oded - 也许我误认为在 XP 上可用,因为我面前没有 XP 机器。我目前使用的是 Windows 7。
-
@leaf dev:这已经很晚了,但是在 Windows 资源管理器的上下文菜单中操作的“发送到 => 压缩文件夹”是默认实用程序的一部分。我知道它存在于 Windows Vista 和 Windows 7 中。我认为默认情况下它也存在于 XP 中,但我已经很久没有进行全新的 XP 安装了。