Question

I'm working on a library to treat specific sections of ODT files as Razor templates for a mini reporting engine. It unzips the odt and modifies content.xml, with what appear to be correct results, but the re-zipped file gives me a "general I/O error" when I try to open in it LibreOffice.

Currently I am using C#'s ZipFile.CreateFromDirectory() method to create the zip file. Do I need to do something special in terms of zipping the files together, or is it more likely that my mistake is somewhere else?

Obviously I first thought to check the mimetype file. I have confirmed that treating the group of files as a single zip archive without compressing them (compressionlevel.none) does not work, giving the same error. I surmise this might be because the mimetype file must be the first file in the archive. Is this really the issue and what can I do better?

Was it helpful?

Solution

I ended up using two different zip libraries. DotNetZip's ZipOutputStream allowed me to specify the mimefile being first and uncompressed. Then I used its ZipFile class to add the necessary folders and their contents. I had had trouble with DotNetZip's Extract() method, so I'm actually using .net's compression library for unzipping the file and DotNetZip to zip it back up.

I'm still looking for a better way to do this, but it works for now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top