-
-
Save tritao/3d66bf98e3e856d1a7d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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