Click here to Skip to main content
13,148,186 members (40,319 online)
Click here to Skip to main content
Articles » Languages » C# » Utilities » Downloads

Stats

162.7K views
8.3K downloads
44 bookmarked
Posted 14 Sep 2007

Make a Zip/UnZip Software using SharpZipLib

, 14 Sep 2007
This article shows how to use SharpZipLib to make a small Zip/UnZip software easily
ICSharpCode.SharpZipLib.dll
ZipTest.exe
ZipTest
ZipTest.suo
bin
Debug
ICSharpCode.SharpZipLib.dll
ZipTest.exe
ZipTest.vshost.exe
ICSharpCode.SharpZipLib.dll
Properties
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.SharpZipLib.Zip;
using System.IO;
using System.Threading;

namespace ZipTest
{
    public partial class FormZip : Form
    {
        public FormZip()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            radioButtonZip.Checked = true;
        }

        private void buttonOpenFile_Click(object sender, EventArgs e)
        {
            //show a openfiledialog to select a file
            OpenFileDialog f = new OpenFileDialog();
            f.Multiselect = false;
            if (f.ShowDialog() == DialogResult.OK)
            {
                textBoxFileName.Text = f.FileName;
            }
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (textBoxFileName.Text != "")
            {
                if (radioButtonZip.Checked == true)
                {
                    //start a new thread to zip it
                    Thread th = new Thread(new ThreadStart(Zip));
                    th.Start();
                }
                else
                {
                    //start a new thread to unzip it
                    Thread th = new Thread(new ThreadStart(UnZip));
                    th.Start();
                }
            }
        }

        private void Zip()
        {
            toolStripStatusLabel1.Text = "Zipping...";
            SetButtonOK(false);
            ZipHelp.Zip(textBoxFileName.Text, textBoxFileName.Text + ".zip", 4096);
            toolStripStatusLabel1.Text = "Done";
            SetButtonOK(true);
        }

        private void UnZip()
        {
            toolStripStatusLabel1.Text = "UnZipping...";
            SetButtonOK(false);
            ZipHelp.UnZip(textBoxFileName.Text, Path.GetDirectoryName(textBoxFileName.Text), 4096);
            toolStripStatusLabel1.Text = "Done";
            SetButtonOK(true);
        }

        //the method to set button's state
        private void SetButtonOK(bool Enable)
        {
            if (buttonOK.InvokeRequired)
                buttonOK.Invoke(new SetEnableCallBack(SetButtonOK), new object[] { Enable });
            else
                buttonOK.Enabled = Enable;
        }

        //delegate to call back
        delegate void SetEnableCallBack(bool Enable);
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

flankerfc
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...

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