1

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?

Paladin852
  • 111
  • 5
  • [Related](http://stackoverflow.com/q/4957212/1997232). – Sinatr Jun 05 '14 at 14:51
  • I wondered whether compressing the mimetype file might be the problem, but people I have been in contact with said they had no trouble reading files after rezipping them with, I.E. 7-zip. This led me to believe that the issue lay elsewhere. That said, thank you, that is quite useful, but I'm still trying to figure out how to zip the files appropriately with C#. – Paladin852 Jun 05 '14 at 14:58
  • I would further like to note that I have zipped the file with no compression at all, to no avail. I am unable to do so much as comment on the linked question, as answering would obviously not be appropriate. I am continuing to research this issue but am not making any progress. – Paladin852 Jun 06 '14 at 15:05
  • Perhaps you could use external tools? Zip achiever itself, or maybe converters (odt <-> doc) and use other format to change data? – Sinatr Jun 06 '14 at 15:09
  • The object is to do this programmatically in C#, in a fairly lightweight library that can be used in various applications. I'd prefer to use as few external programs as possible since, theoretically, they aren't doing anything I shouldn't be able to do already. Plus the nature of the way I'm changing data (using the Razor engine) makes editing the content.xml file a very desirable method, especially since LibreOffice has special text boxes for input from an external source. (I'm more experienced with Libreoffice than any of the MSOffice apps) – Paladin852 Jun 06 '14 at 15:14
  • If there's something better than .net's built in zip library (besides DotNetZip) I'll look into it though. I *think* I just need to make sure the mimetype file isn't compressed and is the first file in the archive, but I'm so far unable to find a way to do that in C#. – Paladin852 Jun 06 '14 at 15:18

1 Answers1

0

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.

Paladin852
  • 111
  • 5