Creating a ZIP Archive in Memory Using System.IO.Compression
Thanks to http://stackoverflow.com/a/12350106/222748 I got:
using (var memoryStream = new MemoryStream())
{
using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
{
var demoFile = archive.CreateEntry("foo.txt");
using (var entryStream = demoFile.Open())
using (var streamWriter = new StreamWriter(entryStream))
{
streamWriter.Write("Bar!");
}
}
using (var fileStream = new FileStream(@"C:\Temp\test.zip", FileMode.Create))
{
memoryStream.Seek(0, SeekOrigin.Begin);
memoryStream.CopyTo(fileStream);
}
}
So we need to call dispose on ZipArchive before we can use it, which means passing 'true' as the third parameter to the ZipArchive so we can still access the stream after disposing it.
Creating a ZIP Archive in Memory Using System.IO.Compression的更多相关文章
- C# 使用原生 System.IO.Compression 实现 zip 的压缩与解压
zip 是一个非常常见的压缩包格式,本文主要用于说明如何使用代码 文件或文件夹压缩为 zip压缩包及其解压操作, 我们采用的是 微软官方的实现,所以也不需要安装第三方的组件包. 使用的时候记得 usi ...
- 利用System.IO.Compression操作压缩文件
引用: using System.IO.Compression; using (FileStream zipToOpen = new FileStream(@"D:\json.zip&quo ...
- System.TypeLoadException: Could not load type 'System.IO.Compression.CompressionLevel' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
1.提示错误信息: zipSystem.TypeLoadException: Could not load type 'System.IO.Compression.CompressionLevel' ...
- 遇到 Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section的解决办法
用记事本编辑*.EXE.config,在“<system.net>”节点加入<defaultProxy> <proxy usesystemdefault="Fa ...
- Installing MySQL on Microsoft Windows Using a noinstall Zip Archive
这两天在自己的windows上安装了一下mySql数据库,安装使用的是5.7.18版本的 noinstall Zip Archive安装包mysql-5.7.18-win32.zip.由于5.7版本相 ...
- eclipse invalid zip archive lib
eclipse invalid zip archive lib 修改.class文件的编译内容.删除license或找到相应的jar包,放到lib下面,重新编译.
- MySQL Community Server 5.5.56 ZIP Archive 绿色解压版 window安装步骤
MySQL Community Server 5.5.56 ZIP Archive 绿色解压版 window安装步骤 首先 准备好启动配置文件my.ini [mysqld] #设置字符集为utf8 ...
- System.Span, System.Memory,还有System.IO.Pipelines
System.Span, System.Memory,还有System.IO.Pipelines 使用高性能Pipelines构建.NET通讯程序 .NET Standard支持一组新的API,Sys ...
- Mysql下载(on windows-noinstall zip archive)
所有内容,都是针对Mysql5.7.18介绍. 1.首先你需要下载一个完整的包,Mysql目前有两个版本可以使用: a. MySql Enterprise Edition:企业版 b. MySql C ...
随机推荐
- zoj1492 最大团
Maximum Clique Time Limit: 10 Seconds Memory Limit: 32768 KB Given a graph G(V, E), a clique is ...
- awk打开多个文件的方法
1.当awk读取的文件只有两个的时候,比较常用的有三种方法(1)awk 'NR==FNR{...}NR>FNR{...}' file1 file2 (2)awk 'NR==FNR{...}NR! ...
- Lyaer 单弹出层获取数据
案例完整代码如下 var cls = layer.open({ title: "请选择被换班人", type: 2, ...
- Core Foundation框架
转载自:http://blog.csdn.net/weiwangchao_/article/details/7744972 Core Foundation框架 (CoreFoundation.fram ...
- git 笔记1
代码 kamil@ubuntu:~/github/xzdz$ git init Initialized empty Git repository in /home/kamil/github/xzdz/ ...
- linux 误删文件恢复
文档太给力了!误删了几个重要文件,抖抖嗦嗦偷偷恢复了,救了我!!! http://jingyan.baidu.com/article/2f9b480d6c2bcd41cb6cc223.html 注意: ...
- [bzoj1984]月下“毛景树”
Description 毛毛虫经过及时的变形,最终逃过的一劫,离开了菜妈的菜园.毛毛虫经过千山万水,历尽千辛万苦,最后来到了小小的绍兴一中的校园里.爬啊爬~爬啊爬~~毛毛虫爬到了一颗小小的" ...
- uva11426 gcd、欧拉函数
题意:给出N,求所有满足i<j<=N的gcd(i,j)之和 这题去年做过一次... 设f(n)=gcd(1,n)+gcd(2,n)+......+gcd(n-1,n),那么answer=S ...
- Circular Queue Implementation Principle
目录 . 引言 . 环形队列的实现原理 . 环形队列编程实现 . 环形队列的内核实现 1. 引言 环形队列是在实际编程极为有用的数据结构,它有如下特点 . 它是一个首尾相连的FIFO(First In ...
- 大一上学期C语言学习心得总结
经过一个学期的C语言学习,大体算是在这个编程语言上入了门,能够通过一些代码解决特定的问题.当然,每次成功将问题转换成代码都小有激动,虽然只是在黑框上输出了一些数字或是字符串. 编程,虽然还不是很懂,但 ...