Edit: If you want to use the code, you have to make a Properties.txt file, the first line is the source folder, second is the dest. file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
namespace Zipping
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void btnCompress_Click(object sender, EventArgs e)
{
//File format should be line by line
//1st line = src folder to compress
//2nd line = destination zip (ext. required)
string AttributesPath = (Application.StartupPath + "\\Properties.txt");
StreamReader reader = new StreamReader(AttributesPath);
string[ ] Attributes = new string[200];
int Counter = 0;
while (reader.EndOfStream == false)
{
Attributes[Counter] = reader.ReadLine(); //Src folder\file on element 0, Dest file on 1
// (zip file).
Counter++;
}
string destfile;//where to place
//the contents that were compressed.
//The Folder to compress
string srcfolder;
Counter = 0;
while (Counter < Attributes.Length & Attributes[Counter] != null)
{
srcfolder = Attributes[Counter];
Counter++;
destfile = Attributes[Counter];
Counter++;
if (File.Exists(destfile) == false)
{
FileStream fs = File.Create(destfile);
//Hex representation of an empty zip file (created by another program)
byte[ ] emptyzip = new byte[ ]{80,75,5,6,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
fs.Write(emptyzip, 0, emptyzip.Length);
fs.Flush();
fs.Close();
}
//Copy a folder and its contents into the newly created zip file
Shell32.ShellClass sc = new Shell32.ShellClass();
Shell32.Folder SrcFlder = sc.NameSpace(srcfolder);
Shell32.Folder DestFlder = sc.NameSpace(destfile);
Shell32.FolderItems items = SrcFlder.Items;
DestFlder.CopyHere( items, 20);
Thread.Sleep(4000);
}
}
}
}