解压缩文件编程.NET中 [英] Unzip files programmatically in .net
问题描述
我想以编程方式解压压缩文件。
I am trying to programatically unzip a zipped file.
我一直在使用.NET中的 System.IO.Com pression.GZipStream
类试过了,但是当我的应用程序运行(实际上是一个单元测试)我得到此异常:
I have tried using the System.IO.Compression.GZipStream
class in .NET, but when my app runs (actually a unit test) I get this exception:
System.IO.InvalidDataException:幻数在gzip头信息是不正确的。请确保您传递一个gzip流。
System.IO.InvalidDataException: The magic number in GZip header is not correct. Make sure you are passing in a GZip stream..
我现在认识到,一个 .zip文件
文件是不一样的。广州
文件,并且的GZip
是不一样的邮编
。
I now realize that a .zip
file is not the same as a .gz
file, and that GZip
is not the same as Zip
.
不过,由于我能够通过手动双击压缩文件,然后点击提取所有文件提取文件 - 按钮,我认为应该有这样做,在code以及的一种方式。
However, since I'm able to extract the file by manually double clicking the zipped file and then clicking the "Extract all files"-button, I think there should be a way of doing that in code as well.
所以我试图用的Process.Start()
与路径压缩文件作为输入。这使我的应用程序打开显示压缩文件内容的窗口。这是所有罚款,但应用程序将没有围绕一个服务器上安装点击提取所有文件 - 按钮。
Therefore I've tried to use Process.Start()
with the path to the zipped file as input. This causes my app to open a Window showing the contents in the zipped file. That's all fine, but the app will be installed on a server with none around to click the "Extract all files"-button.
那么,如何让我的应用程序以提取压缩文件中的文件?
So, how do I get my app to extract the files in the zipped files?
或者是有另一种方式来做到这一点?我preFER在code这样做,无需下载任何第三方库或应用;安全部门是不是太花哨有关...
Or is there another way to do it? I prefer doing it in code, without downloading any third party libraries or apps; the security department ain't too fancy about that...
推荐答案
我们已经使用 SharpZipLib 成功地在很多项目。我知道这是一个第三方工具,但包含的源$ C $ c和可以提供一些见解,如果你选择在这里推倒重来。
We have used SharpZipLib successfully on many projects. I know it's a third party tool, but source code is included and could provide some insight if you chose to reinvent the wheel here.
这篇关于解压缩文件编程.NET中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!