zoukankan      html  css  js  c++  java
  • 压缩文件

    准备工作: 在程序包管理器控制台安装 Install-Package SharpZipLib 引用 using ICSharpCode.SharpZipLib.Zip;

    页面:

     

    代码如下:

    复制代码
       //打开要压缩的文件
       private void button1_Click(object sender, EventArgs e)
        {
          //打开文件
            OpenFileDialog openFile = new OpenFileDialog();
            if (openFile.ShowDialog()==DialogResult.OK)
            {
                textBox1.Text = openFile.FileName;
            }
        }
        //选择压缩后保存的路径
        private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog openFile2 = new FolderBrowserDialog();
            if (openFile2.ShowDialog()==DialogResult.OK)
            {
                textBox2.Text = openFile2.SelectedPath+@"	ext.Zip";
            }
        }
       //确认压缩
        private void button3_Click(object sender, EventArgs e)
        {
            //测试保存的路径是否正确
            MessageBox.Show(textBox2.Text);
            using (ZipFile zip = ZipFile.Create(textBox2.Text))
            {
                zip.BeginUpdate();
                zip.Add(textBox1.Text);
                zip.CommitUpdate();
            }
        }
  • 相关阅读:
    关于DRY原则
    类型之惑
    ThoughtWorks测试
    编程非易事
    瀑布与迭代的真实区别
    对TDD原则的理解
    自我练习
    C# CreateProcess的测试
    乱侃OOD
    复杂系统的五个属性
  • 原文地址:https://www.cnblogs.com/gbb44/p/10640741.html
Copyright © 2011-2022 走看看