This project is read-only.

Library in combination with creation .epub file

Nov 23, 2009 at 9:58 PM

I'm encountering the following problem...

For an validated .epub file it's necessarry to insert (as the first file) an uncompressed mimetype file with the following content (without any linefeed/linetermination ..)


I do this with this code:




ZipFile zip = new ZipFile();
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Level0; // tried .None also
zip.AddFile(System.IO.Path.Combine(f_WorkingFolder, "mimetype"), "");
If you look at my file with a hex editor, it should have application/epub+zip at bytes 0x26 to 0x3A, immediately following the mimetype filename.
In the zipped file the mimetype filename is in the right place, but the file contents doesn't immediately follow it.
Als a result..the .epub file can't be validated
Any thoughts...or even better...a solution ?
Nov 23, 2009 at 10:44 PM

I don't understand.

Why are you looking at the zip file with a hex editor?  What's the problem with the zip file - is it not being read successfully?

If you want to insert a file like that, I suggest something like this:

using (ZipFile zip = new ZipFile())
  var e = zip.AddEntry("mimetype", "application/epub+zip");
  e.CompressionLevel = Ionic.Zlib.CompressionLevel.None; 
  // add other files here
  // ...

The AddEntry() will insert an entry into the zip file with the given name, and the given content. Check the doc for more info.

Also, You can set the CompressionLevel on an individual entry or on the entire file. I'm not sure which you need to do, but my code shows how to do it on the individual entry.

By default, Zip entries created by DotNetZip will include extra data, for the timestamp on the file. This data will appear in the zip file immediately after the filename, and immediately before the file content. Normally this is tolerated by zip tools that read the files.  In some cases it is not.  To turn off the timestamp, set EmitTimesInWindowsFormatWhenSaving to false, on the ZipEntry.  This would be (e.EmitTimesInWindowsFormatWhenSaving = false;)

That will eliminate the extra data between the filename and the file content.


Nov 24, 2009 at 8:06 AM

Hi Cheeso,

I didn't invent the rules:

I've posted my mimefile to some .epub wizards and they came up with the hex differences.

Thank you for your info. I will look into it your solutions..


Nov 24, 2009 at 8:30 AM


Thank you worked...