Reputation: 1859
I am using Entity Framework as part of a school/course project where users should be allowed to upload files or directories. If it's a directory it has to be zipped(I got hold of DotNetZip) but I am not sure of how convert the zip file into a byte[]
. Also should I store the zip in the temp directory and delete it once it has been saved?
Upvotes: 1
Views: 3202
Reputation: 3956
According to http://dotnetzip.codeplex.com/wikipage?title=CS-Examples&referringTitle=Examples, you can save the zip file to a memory stream without writing it to any temporary file:
var stream = new System.IO.MemoryStream();
using (ZipFile zip = new ZipFile())
{
zip.AddFile("ReadMe.txt");
zip.AddFile("7440-N49th.png");
zip.AddFile("2008_Annual_Report.pdf");
zip.Save(stream);
}
byte[] data = stream.ToArray();
Upvotes: 3