Search code examples
c#zipsystem.io.packaging

Unpacking zip file in c# using System.IO.Packaging


I want to unzip a file in c# using the System.IO.Packaging namespace. I know there is a zip library, but I would rather first explore if I can achieve the same without adding extra dependencies.

Here is my code:

using (var fs = new FileStream(fn1, FileMode.Open)) {
    using (var p = Package.Open(fs)) {
        Console.WriteLine(p.GetRelationships().Count());
        Console.WriteLine(p.GetParts().Count());
    }
}
Console.Read();

Using any zip file I find, I get 0 relationships and 0 parts. What am I doing wrong?


Solution

  • Apparently, though all System.IO.Packaging files are zip files, not all zip files conform to System.IO.Packaging. As such, it is useless for unpacking zip files.