Click here to Skip to main content
13,091,093 members (51,464 online)
Click here to Skip to main content
Add your own
alternative version


44 bookmarked
Posted 14 Sep 2007

Make a Zip/UnZip Software using SharpZipLib

, 14 Sep 2007
Rate this:
Please Sign up or sign in to vote.
This article shows how to use SharpZipLib to make a small Zip/UnZip software easily
Screenshot - cp.jpg


This article shows a simple way to make a Zip/UnZip software using SharpZipLib.


SharpZipLib is a very nice OpenSource library. It's a Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform. See this link.

Using the Code

You should use FileStream class as input/output. ZipInputStream and ZipOutputStream are two important classes in the project. ZipInputStream is used to unzip the zipped data to ordinary data. ZipOutputStream is used to zip the ordinary data to zipped data. And there is another class called ZipEntry. ZipEntry is an item zipped in the *.zip file.

I use a new thread to do the zip/unzip work because the large file may lead to the UI form not responding.

This is the zip method:

public static void Zip(string SrcFile, string DstFile, int BufferSize)
    FileStream fileStreamIn = new FileStream
		(SrcFile, FileMode.Open, FileAccess.Read);
    FileStream fileStreamOut = new FileStream
		(DstFile, FileMode.Create, FileAccess.Write);
    ZipOutputStream zipOutStream = new ZipOutputStream(fileStreamOut);
    byte[] buffer = new byte<buffersize />;
    ZipEntry entry = new ZipEntry(Path.GetFileName(SrcFile));
    int size;
        size = fileStreamIn.Read(buffer, 0, buffer.Length);
        zipOutStream.Write(buffer, 0, size);
    } while (size > 0);

This is the unzip method:

public static void UnZip(string SrcFile, string DstFile, int BufferSize)
    FileStream fileStreamIn = new FileStream
		(SrcFile, FileMode.Open, FileAccess.Read);
    ZipInputStream zipInStream = new ZipInputStream(fileStreamIn);
    ZipEntry entry = zipInStream.GetNextEntry();
    FileStream fileStreamOut = new FileStream
		(DstFile + @"\" + entry.Name, FileMode.Create, FileAccess.Write);
    int size;
    byte[] buffer = new byte<buffersize />;
        size = zipInStream.Read(buffer, 0, buffer.Length);
        fileStreamOut.Write(buffer, 0, size);
    } while (size > 0);

Points of Interest

So you can see that it's very easy to make a small Zip/UnZip software. SharpZipLib is very powerful and you can do a lot of things with it.


  • 14th September, 2007 -- Article uploaded


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
China China
I live in Xi'an(西安). It has 3000+ years history and is one of the birthplaces of the ancient civilization of China.
accelerate your life.

You may also be interested in...


Comments and Discussions

GeneralFastZip class Pin
Ramon Smits28-Apr-09 3:16
memberRamon Smits28-Apr-09 3:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170813.1 | Last Updated 14 Sep 2007
Article Copyright 2007 by flankerfc
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid