I'm trying to zip a PDF file, it creates zip file correctly, but if I try to open compressed PDF file, it show me error message "Corrupted file" (I'm trying to open by my PDF reader), where I wrong?
using
(Stream stream = File.Open(fileFullName, FileMode.Create))
{
using
(ZipArchive archive =
new
ZipArchive(stream, ZipArchiveMode.Create,
false
,
null
))
{
using
(ZipArchiveEntry entry = archive.CreateEntry(fi.Name))
{
var writer =
new
StreamWriter(entry.Open());
using
(Stream streamFileToZip = File.Open(fi.FullName, FileMode.Open))
{
var buffer =
new
byte
[4096];
int
sourceBytes = 0;
do
{
sourceBytes = streamFileToZip.Read(buffer, 0, buffer.Length);
writer.Write(buffer);
}
while
(sourceBytes > 0);
}
writer.Flush();
}
}
}