DotNetZip: Convert ZipFile to byte[] array

okello picture okello · Jun 20, 2012 · Viewed 9k times · Source

I'm using DotNetZip to add a file to a zip archive, which I've read from the file system. I'd like to convert the resulting ZipFile to byte[] array. Any assistance will be highly appreciated. My code is shown below.

public byte[] AddPrjFile(FileStream shapeFileZip, Uri prjLocation)
{
    string prjFileAbsPath = prjLocation.AbsolutePath;
    using (ZipFile zip = ZipFile.Read(shapFileZip))
    {
        ZipEntry e = zip.AddFile(prjFileAbsPath);
        e.FileName = zipFile.Name + ".prj";
    }

    return byte_array;
}

Answer

Uwe Keim picture Uwe Keim · Jun 20, 2012

You could simply use the File.ReadAllBytes static method like:

return File.ReadAllBytes( shapeFileZip.Name );

To read from your file.