如何使用 .NET 创建 7-Zip 档案? [英] How do I create 7-Zip archives with .NET?

查看:31
本文介绍了如何使用 .NET 创建 7-Zip 档案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从我的 C# 控制台应用程序创建 7-Zip 档案?我需要能够使用常规的、广泛使用的 7-Zip 程序提取档案.><小时>

这是我的结果,并提供了作为此问题答案的示例

  • 脱壳"到 7z.exe - 这是最简单、最有效的方法,我可以确认它运行良好.正如 workmad3 提到的,我只需要保证所有目标机器上都安装了 7z.exe,这是我可以保证的.
  • 7Zip in内存压缩 - 这是指在发送到客户端之前压缩内存中"cookie;这种方法似乎有些有希望.包装方法(包装 LZMA SDK)返回类型 byte[].当我将 byte[] 数组写入文件时,我无法使用 7-Zip 提取它(File.7z is not supported archive).
  • 7zSharp 包装器(在 CodePlex 上找到) - 这包装了 7z exe/LZMA SDK.我从我的应用程序中引用了该项目,它成功创建了一些存档文件,但我无法使用常规 7-Zip 程序提取文件(File.7z is not supported archive).莉>
  • 7Zip SDK aka LZMA SDK - 我想我不够聪明了解如何使用它(这就是我在这里发布的原因)...任何演示如何创建 7zip 存档的工作代码示例,该存档可以由常规 7zip 程序提取?
  • 用于 7-Zip 存档 DLL 的 CodeProject C# (.NET) 接口 -仅支持从 7zip 档案中提取...我需要创建它们!
  • SharpZipLib - 根据他们的 FAQ,SharpZipLib 不支持 7zip.

解决方案

如果您能保证 7-zip 应用程序将安装(并在路径中)在所有目标机器上,您可以通过调用命令行应用程序 7z 进行卸载.不是最优雅的解决方案,但它是最少的工作.

How can I create 7-Zip archives from my C# console application? I need to be able to extract the archives using the regular, widely available 7-Zip program.


Here are my results with the examples provided as answers to this question

  • "Shelling out" to 7z.exe - this is the simplest and most effective approach, and I can confirm that it works nicely. As workmad3 mentions, I just need to guarantee that 7z.exe is installed on all target machines, which is something I can guarantee.
  • 7Zip in memory compression - this refers to compressing cookies "in-memory" before sending to the client; this method seems somewhat promising. The wrapper methods (wrapping the LZMA SDK) return type byte[]. When I write the byte[] array to a file, I can't extract it using 7-Zip (File.7z is not supported archive).
  • 7zSharp Wrapper (found on CodePlex) - this wraps the 7z exe/LZMA SDK. I referenced the project from my app, and it successfully created some archive files, but I was unable to extract the files using the regular 7-Zip program (File.7z is not supported archive).
  • 7Zip SDK aka LZMA SDK - I guess I'm not smart enough to figure out how to use this (which is why I posted here)... Any working code examples that demonstrate creating a 7zip archive that is able to be extracted by the regular 7zip program?
  • CodeProject C# (.NET) Interface for 7-Zip Archive DLLs - only supports extracting from 7zip archives... I need to create them!
  • SharpZipLib - According to their FAQ, SharpZipLib doesn't support 7zip.

解决方案

If you can guarantee the 7-zip app will be installed (and in the path) on all target machines, you can offload by calling the command line app 7z. Not the most elegant solution but it is the least work.

这篇关于如何使用 .NET 创建 7-Zip 档案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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