Skip to content

Instantly share code, notes, and snippets.

@tritao tritao/zip.cs Secret
Created Sep 4, 2015

Embed
What would you like to do?
using System.IO;
using System.IO.Compression;
namespace ZipIssue
{
class MainClass
{
public static void Main(string[] args)
{
// The following produces a zip file that is of an old enough format that if used to create .xlsx Open XML
// files won't allow such files to be opened by Excel.
using (FileStream zipStream = new FileStream(@"z1.zip", FileMode.Create))
using (ZipArchive zipArchive = new ZipArchive(zipStream, ZipArchiveMode.Create,
true, System.Text.Encoding.UTF8))
{
ZipArchiveEntry zipEntry = zipArchive.CreateEntry("filea");
Stream zipEntryStream = zipEntry.Open();
byte[] chars = System.Text.Encoding.UTF8.GetBytes("abc xyz");
zipEntryStream.Write(chars, 0, chars.Length);
zipEntryStream.Close();
zipEntry = zipArchive.CreateEntry("fileb");
zipEntryStream = zipEntry.Open();
zipEntryStream.Write(chars, 0, chars.Length);
zipEntryStream.Close();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.