1、示例图(WinForm窗体应用程序)
2、首先下载SharpZipLib插件
3、代码
public partial class Form1 : Form { public Form1() { InitializeComponent(); } //选择文件1 private void button1_Click(object sender, EventArgs e) { DialogResult dia = openFileDialog1.ShowDialog(); if (dia == DialogResult.OK) { txtFile1.Text = openFileDialog1.FileName; } } //选择文件2 private void button2_Click(object sender, EventArgs e) { DialogResult dia = openFileDialog1.ShowDialog(); if (dia == DialogResult.OK) { txtFile2.Text = openFileDialog1.FileName; } } //压缩位置 private void button3_Click(object sender, EventArgs e) { DialogResult dia = saveFileDialog1.ShowDialog(); if (dia == DialogResult.OK) { txtWei.Text = saveFileDialog1.FileName; } } //开始压缩 private void button4_Click(object sender, EventArgs e) { string path = txtWei.Text; ZipFile zip = ZipFile.Create(path); zip.BeginUpdate(); zip.Add(txtFile1.Text); zip.Add(txtFile2.Text); zip.Password = txtPwd.Text;//密码 zip.SetComment(txtDes.Text);//备注 zip.CommitUpdate(); MessageBox.Show("压缩完成"); } }