• 文件压缩


    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("压缩完成");
            }
        }
  • 相关阅读:
    C语言I博客作业07
    C语言I博客作业06
    C语言I博客作业05
    C语言I博客作业04
    C语言I博客作业02
    Django连接MySql数据库
    asyncio异步编程
    Django-rest framework框架
    Git版本管理工具详细教程
    MySQL的sql_mode模式说明及设置
  • 原文地址:https://www.cnblogs.com/dujian123/p/10582728.html
Copyright © 2020-2023  润新知