예제 #1
0
        //执行文件解压
        private void btnUnzip_Click(object sender, EventArgs e)
        {
            string zipFile = this.txtZipFile.Text;

            if (!File.Exists(zipFile))
            {
                MessageBox.Show("要解压的文件路径不正确,请重新选择!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (this.folderBrowserDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            string password   = this.txtUnzipPassword.Text;
            string destFolder = this.folderBrowserDialog1.SelectedPath;

            try
            {
                if (SharpZip.DecomparessFile(zipFile, destFolder, password))
                {
                    MessageBox.Show("完成解压文件。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Process.Start("explorer.exe", "/select, " + destFolder);//打开资源管理器并选中文件夹
                }
                else
                {
                    MessageBox.Show("解压文件失败!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #2
0
        private void btnZip_Click(object sender, EventArgs e)
        {
            if (this.lstFile.Items.Count == 0)
            {
                MessageBox.Show("请添加要压缩的文件!");
                return;
            }


            if (this.saveFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            string zipFilePath = this.saveFileDialog1.FileName;

            var fileList = new List <string>();

            foreach (var item in this.lstFile.Items)
            {
                var filePath = item.ToString();
                if (!fileList.Contains(filePath))
                {
                    fileList.Add(filePath);
                }
            }

            string comment  = this.txtComment.Text;
            string password = this.txtPassword.Text;
            int    level    = (int)this.numZipLevel.Value;

            try
            {
                if (SharpZip.CompressFile(fileList, zipFilePath, comment, password, level))
                {
                    MessageBox.Show("完成文件压缩。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Process.Start("explorer.exe", "/select, " + zipFilePath);//打开资源管理器并选中文件
                }
                else
                {
                    MessageBox.Show("文件压缩失败。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }