I am using sharpCompress (http://sharpcompress.codeplex.com/) to compress and decompress a file:
public void compressZip(string in, string out)
{
try
{
using (var archive = ZipArchive.Create())
{
archive.AddEntry(file2Compressed, new FileInfo(int));
var fs= new FileStream(file2Saved, FileMode.CreateNew);
archive.SaveTo(memoryStream, CompressionType.Deflate);
}
using (Stream stream = File.OpenRead(out))
using (var reader = ZipReader.Open(stream))
{
if(!reader.Entry.IsDirectory)//exception here
using (Stream newStream = File.Create("123" + in))
reader.WriteEntryTo(newStream);
}
}
catch (Exception ex)
{
Console.WriteLine("Ex: " + ex.Message);
}
}
I got an exception at: ‘exception here’, reference is not an object… I have no clue why it is like that. Any idea?
Thanks in advance.
You’re not calling
reader.MoveToNextEntry(), so the reader is “before” the first entry. You should be using something like: