This project is read-only.

OpenXML documents - Sample Code?

Jul 14, 2011 at 11:49 AM


I create OpenXML documents. For Zipping I use:

Using zip As Ionic.Utils.Zip.ZipFile = New Ionic.Utils.Zip.ZipFile(targetNewName, Console.Out)
    zip.AddDirectory(tempFolder, "")
End Using

and then I rename the file to Filename.pptm

This File works not.

If I zip this tempFolder via WinZip (Compression: „Super Fast“) the file works fine.

Documentation Open Packaging Convention“:
"The compression algorithm supported is DEFLATE, as described in the .ZIP specification. The package
implementer shall not use any compression algorithm other than DEFLATE."

How can I create this zip file using DotNetZip Library.
Can you send me a sample Code?

Thanks and best regards

Jul 14, 2011 at 12:45 PM


I found a way ;-)

Using zip As Ionic.Zip.ZipFile = New Ionic.Zip.ZipFile(targetNewName)
    zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Level0
End Using


Thanks and best regards

Jul 14, 2011 at 1:35 PM

Yes - seems good to me.  With your code, the files in the tempFolder are not compressed at all.  They are "stored". 

That seems to directly oppose the OPC spec, which says "use DEFLATE".  Also it's my understanding that WinZip's "superfast" uses DEFLATE.

But your code works for you, that is the proof, isn't it ?


Jul 14, 2011 at 1:40 PM

Hello Cheeso,

thanks for your answer.

What would be the correct code for the OPC spec "use DEFLATE" ?

Thanks and best regards

Jul 14, 2011 at 3:57 PM
Edited Jul 14, 2011 at 3:58 PM

By default, DotNetZip will use DEFLATE.  If the application does not set the CompressionLevel property, or sets it to a value that is not ZERO (implies no compression at all), then DEFLATE is the algorithm employed.  DEFLATE has a few options in it, and setting the compressionlevel to some non-zero level (Level6, Level1, Level9, etc) turns those options ON or OFF.  But in all cases, the algorithm is DEFLATE.

I don't know about the OPC spec, and I haven't ever used it.  There have been some users of DotNetZip that have read/extracted OPC format, but I don't recall anyone asking about how to produce a file in OPC format. 

It's surprising to me that you see a difference between the case where you set CompressionLevel=Level0 and the case where you do nothing. It's my understanding that OPC is simply a ZIP format, with a prescribed internal structure.   In that case it should not matter whether you use compression or not - the ZIP format allows the use of compression, or allows "no compression", in other words simply storing the data uncompressed. 

You said the OPC created with regular compression "works not", but you haven't explained just what error you receive.  If I were investigating this, I'd try to get more information as to exactly why it "works not".




Jul 14, 2011 at 4:03 PM

Gunter, just looking at your code a little further, you do have one major difference beyond setting the compression level.

In the first case you have specified AddDirectory(dirName, "").  In the second case you use AddDirectory(dirName) (with no second argument).

I suspect this is the source of the problem - not the compression level.   You need to use No second argument when you call AddDirectory - it preserves the directory structure within the zip file.   If you simply DO NOT set the CompressionLevel, you will get the default compression, which is DEFLATE, and I suspect all will work.



Jul 14, 2011 at 4:08 PM

Hello Chesso,

Thanks for your answer.

Works not: If i open the file createt from Post1: "Filename.pptm" in PowerPoint 2010 = PowerPoint crash.
(DotNetZip Library Ver:

With the code from Post 2: PowerPoint opens the file.
(DotNetZip Library Ver:

Thanks and best regards

Jul 14, 2011 at 4:14 PM

ok, so it's all working, yes?


Jul 14, 2011 at 4:26 PM

Hello Chesso,

Yes. Thank you for your help!

Best Regards