To extract a file from a zip to a memory variable (for instance, a Byte array), use the following function.
Make sure to add these using statements at the top of the code:
using C1.C1Zip;
using System.IO;
C# |
Copy Code
|
---|---|
private byte[] GetDataFromZipFile(string zipFileName, string entryName) { // Get the entry from the zip file. C1ZipFile zip = new C1ZipFile(); zip.Open(zipFileName); C1ZipEntry ze = zip.Entries[entryName]; // Copy the entry data into a memory stream. MemoryStream ms = new MemoryStream(); byte[] buf = new byte[1000]; using (Stream s = ze.OpenReader()) { for (;;) { int read = s.Read(buf, 0, buf.Length); if (read == 0) break; ms.Write(buf, 0, read); } } // There's no need to call close because of the C# 'using' // statement above but in VB this would be necessary. //s.Close(); // Return result. return ms.ToArray(); } |