Search code examples
c#bytedotnetzip

DotNetZip: Convert ZipFile to byte[] array


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;
}

Solution

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

    return File.ReadAllBytes( shapeFileZip.Name );
    

    To read from your file.