Hey there, i am trying to zip .bak files while making the backup , this application schedules backups and then backs up databases on the server , so now i want to zip or compres these files , can anyone give me some advise on how to do this ??

private void openfiledialog_Click(object sender, EventArgs e)
            textBox1.Text = openFileDialog1.FileName;

        private void LetsZIPIT(object sender, EventArgs e)
                FileStream m_FileStream = File.Open(textBox1.Text, FileMode.OpenOrCreate);
                GZipStream ZipStream = new GZipStream(m_FileStream, CompressionMode.Compress, true);
                //ZipStream.Write(byte[], 0, 1);
            catch (Exception E)

        private void btnzip_Click(object sender, EventArgs e)
            LetsZIPPPIT(sender, e);

This just takes all the data out of the file .... i feel stupid for no knowing this ...

Any example will be amazing , even if its just to zip a text file , i will play with the code,


mr Von Zipper

ZipStream.Write(byte[], 0, 1); ?

byte[] is a declaration of a byte array, where is the variable and where is this variable assigned?
The last parameter is 1 are you going to compress 1 byte? This should be the lenght of the bytes you are trying to compress.
Never feel stupid when you think there is something you don't know! If that was the case I would feel like one of the most stupid people in the world!

commented: nice help +4

Im switching to the


Seems a bit more reliable...

Whats up beautiful people

the fresh air today (because my code works)...

I thought I'd swing by to give you guys the code also because this could be confusing as many of us never ever used it ... its simple and it works...
1. Two Textboxes (txtSourcePath, txtDestpath)
2. Two buttons (btnZip, btnBrowse)
3. An open file dialog (openfiledialog1)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Compression;
using System.IO;

namespace TestDummyTWO
    public partial class Form1 : Form
        string srcPath;
        string destPath;
        private const int buffer_size = 100;

        public Form1()

        private void btnBrowse_Click(object sender, EventArgs e)
            txtSourcePath.Text = openFileDialog1.FileName;
            txtDestPath.Text = "C:/Documents and Settings/All Users/Desktop/Tester.zip";

        private void btnzip_Click(object sender, EventArgs e)
            zIpDatabseFile(srcPath, destPath);

        // creating the Zip File
        private void zIpDatabseFile(string srcPath, string destPath)
            //This is for  Zip a File
            byte[] bufferWrite;
            FileStream fsSource;
            FileStream fsDest;
            GZipStream gzCompressed;
            fsSource = new FileStream(txtSourcePath.Text, FileMode.Open, FileAccess.Read, FileShare.Read);
            bufferWrite = new byte[fsSource.Length];
            fsSource.Read(bufferWrite, 0, bufferWrite.Length);
            fsDest = new FileStream(txtDestPath.Text, FileMode.OpenOrCreate, FileAccess.Write);
            gzCompressed = new GZipStream(fsDest, CompressionMode.Compress, true);
            gzCompressed.Write(bufferWrite, 0, bufferWrite.Length);

Special thanks to ddanbe for the motivation , i really needed it yesterday...

Happy coding people

Very nice cVz. I am happy when you are. You have posted your last message in the code snippets.