Share

About the Author

I got my BS in Software Engineering from Iran, worked there for 4.5 years mainly in industrial automation field. Then I moved to Australia. In Australia, I had a great chance to work at some big companies. Since 2009 I have been living in the States. I received my MS in Information Systems from Illinois State University. Currently, I am a Senior Software Development Engineer.

Comments and Discussions

Discussions posted for
the Published version of this article. Posting a message here will take you to the publicly
available article in order to continue your conversation in public.

One problem annoyance was the xml file that was added into the zip as I mention in the article. Never looked into seeing if there was other ways of doing it without generating the file or removing it post compression.

That XML is required by the Packaging namespace. If you remove it, then you won't be able to decompress it using Packaging Zip methods. In detail, the packaging namespace is there to create Windows-compatible packages like CAB archives.
In .NET 5, the System.IO.Compression contains all required methods to create/read standard Zip archives. Once you upgraded your projects to .NET 5, I highly recommend to use the new methods instead of these.
The main reason I created this tip was because at the time there was no built-in methods to work with zip archives and I personally don't like the idea of using 3rd party code unless there is no other options.
If you have an old .NET project which cannot add a reference to WindowsBase.dll, then use vjslib.dll (J#) for compression.
Here is an article[^] which tells how to do that

... edit: suggestion: clarify for the reader that the purpose of this example is to create a zipped folder (package) from a set of files, or to unzip a set of zipped files in a zipped folder (package) ...

0. In spite of the fact that WindowsBase.dll is notoriously hard to find [^], the author doesn't bother to mention that, or help the reader find it.

1. the author of this article states, in a response, to a message: "There is an alternate version for .NET 3.5 in this thread. Please check it out." There is no alternate version link in this article, or the comments.

2. there are alternate methods, clearly documented by MSDN, that do not require a reference to WindowsBase.dll.

Note that in .NET 4.5 "WindowsBase.dll" is considered an "obsolete" Type: [^], which does not mean this cannot work in 4.5.

fyi: on my current system (Win 8/64), Visual Studio 2012. There are 37 instances of WindowsBase.dll ! Some are specific to WPF.

Dear BillWoodruff,
Not sure about what you mean by most of what you said. It appears you are either new to .NET world or you are using a tool different than Visual Studio to write .NET code.
This tip was written with the assumption that you use VS and since it is a tip I did not feel that I needed to mention you need to use VS. In VS if you right click on your project references and select 'Add Reference' and then having 'Framework' selected, it shows 'WindowsBase' as an assembly that you can add to your project as a reference. This has been tested by myself and all people here apparently since no one complained about it.
Regarding alternate version: again I think you are not familiar with CodeProject I guess! On the left column on page there is a link 'Alternatives (1)'. When in CodeProject someone says alternate version and there is no link they refer to that link where users can contribute to tips/articles and suggest alternate versions of it for different reasons.
In .NET 4.5 I already know that it comes with Zip support in IO namespace but developers cannot upgrade their production to new version right away! It takes time and till then we need to use what we have. BTW, this tip goes back to over a year ago when there was no talk about 4.5.
I hope this answered your concerns and issues on this tip.

Not sure about what you mean by most of what you said. It appears you are either new to .NET world or you are using a tool different than Visual Studio to write .NET code.

This is what is known an an ad hominem attack by impugning credibility; what you really mean: is that you felt irritated, and didn't like, what I said to you.

If you wish to use some "perceived slight" as an excuse to ignore the constructive feedback, and information, in my response, that's up to you.

You are correct, however: I wasn't aware of an "Alternative version" link on the CP page; something I've never seen before. It would have been much better form, and taken you less than two seconds, to have put in a direct link to the alternative in your body-text.

In my mind, a vote of #3 is not a negative vote, and I never implied, in any of my statements, that your Tip-Trick was not useful, and valuable.

~
“This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal

Still not sure if I understood what you mean
In reply to the point you brought up that which version of WindowsBase you need to use or where its location is I said that and mentioned it's all in VS.
Regarding what you understood from what I said -
1. I am not a celebrity kind of person so I do not check on them and don't know what they say
2. I am not irritated with what you said because here is a learning area and check on this tip comments and see how many times I accepted what others said and changed the code and improved it.

And vote of 3 is your choice and you are free to vote and I did not try, am not trying, and won't try to change peoples' votes but to respect them because that's what they think is true - not necessarily from my point of view but that doesn't matter because it is not my vote

What I wanted to tell was to check on VS capabilities and get more familiar with one of the greatest DEV tools in the world and CodeProject - the ultimate code sharing site

Hi,
I gone through your code and try to implement the same. But it's not working for me to unzip a zipfile.

I am pasing parameters zipPath and baseFolder to Unzip() method.
When controls pass to "UnzipFilesFromStream(Stream source, string baseFolder)" method, in "foreach (PackagePart zipPart in package.GetParts())" section, i didn't get anything and control comes out from foreach loop.
I think either "using (Package package = Package.Open(source, FileMode.Open))" or package.GetParts() is not working properly.

Make sure you set the file position to the beginning of the file before you call UnzipFilesFromStream(Stream source, string baseFolder). If that doesn't fix it and you have altered the code presented in the tip, copy and paste your code in the message so I can take a look and figure out what might be wrong.

Sorry, no malice intended here, but this is a general comment for yourself and all posters. The application I develop is targeted at .Net 2.0. As such, no version of WindowsBase.dll is available to me, so your article really needs to EXCLUDE versions pre-3.0. It is an interesting article, and may come in useful to me - someday - but when looking for a solution to a problem, I don't want to read a whole article, then try and implement it only to find I can't because it's targeted at a later framework. We don't all have the luxury of choosing the version of the framework we are working with.

Nice, but please specify .NET version required. In the title, or with Code Project flags or, at a minimum, early in the text. Those of us stuck with using early versions of .NET then need not waste our time. Thanks.

As long as you can make a reference to WindowsBase.dll you should be able to use this code. You may need to change method signatures a little bit though. There is an alternate version for .NET 3.5 in this thread. Please check it out

Then I need to to decode the strings from the "zip" file (Uri encodes spaces to '%20', so we see these '%20' in file and directory names instead of spaces). For example, get the decoded filename like so: