Take the 2-minute tour ×

When reading a zip package using the System.IO.Packaging assembly, I have found that zip files created using the standard windows zip utility are unable to be read (the package parts (internal files) of the zip package show as not existing).

After doing some research it appears that this is because the System.IO.Packaging library adds a Content_Types.xml to the zip when it is created, which does not appear to be present in a standard windows compressed zip.


using (Package Zip = Package.Open(BundlePath, FileMode.Open))
    Uri FileUri = PackUriHelper.CreatePartUri(new Uri("somefile.xml", UriKind.Relative));
    if (!Zip.PartExists (FileUri ))  //this fails even though the file exists in the zip
        throw new ResourceException(String.Format("Zip {0} does not contain file", BundlePath));

Is there anyway to still use the packaging system provided by .NET to read standard zip files, or do they need to be created using the library.


Adding this file (Content_Types.xml) manually, and zipping using the Windows compression utility, proves to be successful in allowing the package to read.


share|improve this question
What is the "standard windows zip utility"? –  Oded Nov 23 '11 at 15:32
@Oded - The default compression utility that comes with Windows XP, Windows 7, etc –  leaf dev Nov 23 '11 at 15:37
I will ask again, as I don't know of one that comes with XP. –  Oded Nov 23 '11 at 15:38
@Oded - Perhaps I am mistaken with one being available on XP as I do not have an XP machine in front of me. I currently am using Windows 7. –  leaf dev Nov 23 '11 at 15:42
@leaf dev: This is quite late, but the "Send To => Compressed Folder" operating in the context menu in Windows Explorer is part of the default utility. I know for a fact that it's there in Windows Vista and Windows 7. I think it's there by default in XP too, but I haven't done a fresh XP install in ages. –  Ethan May 31 '12 at 15:45
add comment

2 Answers

up vote 4 down vote accepted

System.IO.Packaging isn't there to read zip files but packages. Use DotnetZip instead.

share|improve this answer
add comment

Unfortunately I believe you are correct there isn't a good way to get the System.IO.Packaging libraries to open up any file in a standard zip format that doesn't contain that [content_types].xml file.

I was working on this issue a few months back, and this is what I was trying to implement something that would inject this file before we just decided to initially generate all of our files from within .NET:

the format of the zip file is the following

(---file 1---)(---file 2---)...(---file x---)(table of contents)

Without a third party library you should be able to open up a zip file as a binary file, hop to the end and read that table of contents, add a [content_types].xml file at the end with the types/default extension info, adjust the table of contents entries, append it to the end of the file, and go. The problem I was running into when trying to implement this is there are various checksums on the file to verify that it hasn't been corrupted, I hadn't gotten them all by the time I needed to change directions on this.

I'm sure this is more info that you needed, but should you decide to implement your own solution hopefully this helps.

share|improve this answer
add comment

Your Answer


