如何在C#中ZIP文件,不使用第三方API? [英] How do I ZIP a file in C#, using no 3rd-party APIs?

查看:141
本文介绍了如何在C#中ZIP文件,不使用第三方API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很确定这不是一个重复的,所以我忍受一会儿。

I'm pretty sure this is not a duplicate so bear with me for just a minute.

我如何编程(C#)ZIP文件)不使用任何第三方图书馆?我需要一个本机Windows调用或类似的东西;我真的不喜欢开始一个过程的想法,但如果我绝对必须的话。一个PInovke的电话会更好一些。

How can I programatically (C#) ZIP a file (in Windows) without using any third party libraries? I need a native windows call or something like that; I really dislike the idea of starting a process, but I will if I absolutely have to. A PInovke call would be much better.

没有这个,让我告诉你我真正想要完成的事情:我需要让用户下载一个集合的单一请求中的文档。任何有关如何实现这一点的想法?

Failing that, let me tell you what I'm really trying to accomplish: I need the ability to let a user download a collection of documents in a single request. Any ideas on how to accomplish this?

推荐答案

您是否使用.NET 3.5?您可以使用 ZipPackage 类和相关类。它不仅仅是压缩文件列表,因为它需要为您添加的每个文件的MIME类型。它可能会做你想要的。

Are you using .NET 3.5? You could use the ZipPackage class and related classes. Its more than just zipping up a file list because it wants a MIME type for each file you add. It might do what you want.

我正在使用这些类来解决类似的问题,将几个相关的文件存档到一个文件中进行下载。我们使用文件扩展名将下载文件与我们的桌面应用程序相关联。我们遇到的一个小问题是,由于客户端代码无法打开zip文件,所以不可能使用7-zip这样的第三方工具来创建zip文件 - ZipPackage添加了一个描述内容类型的隐藏文件每个组件文件,如果该内容类型文件丢失,则无法打开zip文件。

I'm currently using these classes for a similar problem to archive several related files into a single file for download. We use a file extension to associate the download file with our desktop app. One small problem we ran into was that its not possible to just use a third-party tool like 7-zip to create the zip files because the client side code can't open it -- ZipPackage adds a hidden file describing the content type of each component file and cannot open a zip file if that content type file is missing.

这篇关于如何在C#中ZIP文件,不使用第三方API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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