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

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

问题描述



我如何编程(C#)ZIP一个文件(在Windows中) )而不使用任何第三方库?我需要一个本地的windows调用或类似的东西;我真的不喜欢启动一个过程的想法,但如果我绝对必须。 PInovke调用会好很多。



没有,让我告诉你我真正想完成的事情:我需要让用户下载一个集合的文档在单个请求中。

解决方案

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



我目前使用这些类来解决类似的问题,将多个相关文件归档到一个文件中进行下载。我们使用文件扩展名将下载文件与我们的桌面应用相关联。我们遇到的一个小问题是,它不可能只使用第三方工具,如7-zip来创建zip文件,因为客户端代码无法打开它 - ZipPackage添加一个隐藏文件描述内容类型每个组件文件,如果缺少该内容类型文件,则无法打开zip文件。


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

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?

解决方案

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.

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#中使用没有第三方API的文件ZIP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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