When dealing with Zip files, you have a few choices: use native APIs from third party DLLs, Java APIs, or .NET APIs. If you rush to use APIs from the System.IO.Compress .NET namespace, you will be very disappointed. For reasons only Microsoft knows, the support is limited to streams only, and lacks completely for multi-file archives. This was probably a reason why third party .NET libraries like SharpZipLib cropped up. If you don't trust the free software, you might be surprised to find out that you can find .NET support for multi-file archives in .NET buried in J# assemblies that offer parity with Java APIs. To make a useful application that uses it, I started with an existing CodeProject application that is very handy when backing up source code. I replaced the SharpZipLib references and used the Microsoft J# APIs instead. When porting the application, I noticed that the SharpZipLib APIs were looking very similar with the J# APIs, and that made my work so much easier. To make this utility more enticing to use, I've added quite a few features that I will detail below.

In order to use Microsoft's API for multi-file zips and Java streams, you have to add the vjslib.dll and vjslibcw.dll .NET assemblies as project references. They are part of the J# distribution pack. The Java like types will show up in the java.util.zip namespace. Since Microsoft's documentation on this topic is quite sparse, I often had to rely on intellisense to figure it out. For simplicity's sake, some nonessential UI code is omitted below, and can be found only in the source code provided.

You can not directly modify a Zip file. However, you can create another Zip and copy only select files in it. When the transfer is complete, we can rename the new file as the original and it would look like we changed the Zip. The edited for brevity method below receives a list of strings with the unwanted files:

To make this tool more attractive, I've added some improvements of my own: The first one to notice is the usage of a checked list box that allows doing manual changes on the fly. My favorite is the ability to edit the list of filter extensions that are bound to the CPZipStripper.exe.xml file through a DataTable. Here is an edited snapshot of this file:

Notice that in the application configuration file, we keep not only the appSetttings node, but also the files, paths, and most importantly, the DataTable content. Loading the data from this XML file in the respective lists and the DataSet is easy:

I'm not going to get into the details on this one, but as you've already noticed in the XML snippet, you can use the * and ? chars. It's a good idea that the first thing you do when you open this application is setting the configuration.

As a utility, I consider version 2.x to be an improvement over the old one. You can use it to some extent as a WinZip replacement, but it lacks features like encryption. .NET 2.0 and the J# package have to be installed on your machine to run it. If you have problems running the exe alone, it might be because you are missing the J# distribution package or the .NET 2.0 runtime. If that's the case, I recommend you try to install this MSI install file I've created or download vjredist_32bit.zip and install it locally.

It's not realy a 'Java' dependency, but an assembly resembling Java APIs.
When I wrote this article years ago I did not know about dotNetZip. Usually I try to use stuff that's likely to be supported for a while. In the hindsight, J# is not a prime example of that ('thanks' to Microsoft ), but back then, I thought otherwise.

Actually, System.IO.Packaging isn't that useful for "straight" ZIP archives. It targets "document packages", meaning you need a [Content_Types].xml file at the top level that sets out the content types in the package, etc. and rels files that links things together.

Hey,
Using the java.util.zip, I was able to zip files and folders. But when I try to delete any archive file/folder from the zipped file, manually, an error "The compressed(zipped)folder is invaild or corrupt" is occuring.

This error also occurs while adding any new file/folder into the zip file
Can any one of have faced this situation. Can some one help me with this.

I am tried to delete a file in the archived files MANUALLY and I am unable to delete it. I am not using any tool to delete them. I could extract all files though with out any problem. Are you telling me that I should not use methods provided in java.util.zip library. I am trying zip files without using any third party dlls. Can some suggest what could be going wrong?. I have closed zipoutputstream after adding all files and folders. I can unzip the archived files though.

I don't know what you mean to delete files 'MANUALLY' in a zip archive.
I do some sort of 'deleting' from zip, but that amounts to creating another zip only with the entries I want, deleting the original file, and renaming the new zip as the old one.

when I opened a zip file created, using the java.util.zip library, with the help of the script given above, and deleted a file in the zip file I am getting an error saying th e zip file is corrupt and I am unable to delete the file. Similarly if I add a new file to the zip file I am getting the similar error.

One of my client application uses unzip.dll third party library to unzip archived files. If the internal folder structure uses "\" as path seperators, unzip.dll fails to unzip the archived file. I fixed it by assigning "/" for path seperators in side zip file. I am just providing this information for those using java.util.zip library for zipping files and folders.

I'm writing a program backup folder.but I don't get folder . can you help me to Get folder ?my paragraph code is written :
Private Function GetFileInFolder(ByVal strFolderName As String) As String()
Dim arrFilesString As String()
Dim arrFoldersString As String()
Dim dirString As String
Dim i As Integer
Dim intLength As Integer
Try
If (arrFilesString Is Nothing) Then

If (Not (Directory.GetFiles(strFolderName) Is Nothing)) Then
arrFilesString = Directory.GetFiles(strFolderName)
End If
(strFolderName).Length() - 1
(Directory.GetFiles(strFolderName).GetValue(i), intLength)
End If
Catch
End Try

I'm writing a program backup folder.but I don't get folder . can you help me to Get folder ?my paragraph code is written :
Private Function GetFileInFolder(ByVal strFolderName As String) As String()
Dim arrFilesString As String()
Dim arrFoldersString As String()
Dim dirString As String
Dim i As Integer
Dim intLength As Integer
Try
If (arrFilesString Is Nothing) Then

If (Not (Directory.GetFiles(strFolderName) Is Nothing)) Then
arrFilesString = Directory.GetFiles(strFolderName)
End If
(strFolderName).Length() - 1
(Directory.GetFiles(strFolderName).GetValue(i), intLength)
End If
Catch
End Try

There is an undocumented assembly in the GAC called MICROSOFT.VISUALSTUDIO.ZIP.dll

It did not take long using ildasm to figure out how to use it.

I have been using the classes in this assembly to work with zip files.

The only tricky part is adding a reference to the assembly into a project. It does not show up in the .NET page of the Add Reference dialog. Instead you need to use the Browse tab and work out the full path to the assembly inside the GAC. Do this at a command prompt.