C#:SevenZipSharp使用7z.dll来进行压缩与解压缩
来源:互联网 发布:易游网络验证收费 编辑:程序博客网 时间:2024/06/05 09:35
源程序及演示程序下载地址: 【北方网通】 【电信网通】
【下载说明】
1 点击上面的地址,打开下载页面
2 点击"普通下载"--等待30秒--点击"下载"按钮--保存
程序运行截图如下:
使用7z.dll来解压文件
选择解压到何处
解压完毕。
添加需要压缩的文件
选择保存路径
压缩完毕的提示。
主要源程序:
/* * Created by SharpDevelop. * User: Administrator * Date: 2012/10/29 * Time: 16:13 * * To change this template use Tools | Options | Coding | Edit Standard Headers. */using System;using System.Collections.Generic;using System.Drawing;using System.Windows.Forms;using SevenZip;using SevenZipSharp;namespace SevenZipSharp{/// <summary>/// Description of MainForm./// </summary>public partial class MainForm : Form{SevenZip.SevenZipExtractor extractor = null;SevenZipCompressor compressor = new SevenZipCompressor();public MainForm(){//// The InitializeComponent() call is required for Windows Forms designer support.//InitializeComponent();//// TODO: Add constructor code after the InitializeComponent() call.//this.label1.Text = "Please choose a archive to extract at first.";this.label5.Text = "0";this.label2.Text = "";this.label3.Text = "";this.listBox1.Items.Clear();this.listBox2.Items.Clear();}void ShowException(string msg){MessageBox.Show(msg,"Exception!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);}void ShowInformation(string msg){MessageBox.Show(msg,"Information!",MessageBoxButtons.OK,MessageBoxIcon.Information);}void BtnBrowseCompressedFileClick(object sender, EventArgs e){try{OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = "ZIP File(*.zip)|*.zip|RAR File(*.rar)|*.rar";if(ofd.ShowDialog() == DialogResult.OK){string archiveFullName = ofd.FileName;extractor = new SevenZipExtractor(archiveFullName);extractor.ExtractionFinished += delegate {this.label1.Text = "Extraction Finished.";};extractor.Extracting += delegate {this.label1.Text = "Extracting, please wait...";};extractor.FileExtractionStarted += delegate {this.label1.Text = "Start extracting...";};this.label5.Text = extractor.FilesCount.ToString();this.label2.Text = extractor.PackedSize.ToString() + " bytes";this.listBox1.Items.Clear();foreach(string fileName in extractor.ArchiveFileNames){this.listBox1.Items.Add(fileName);}}}catch(Exception ex){ShowException(ex.Message);}}void BtnExtractClick(object sender, EventArgs e){try{FolderBrowserDialog fbd = new FolderBrowserDialog();if(fbd.ShowDialog() == DialogResult.OK){extractor.ExtractArchive(fbd.SelectedPath);}extractor.Dispose();extractor = null;}catch(Exception ex){ShowException(ex.Message);}}void MainFormFormClosing(object sender, FormClosingEventArgs e){if(extractor != null)extractor.Dispose();}void BtnAddFileClick(object sender, EventArgs e){try{OpenFileDialog ofd = new OpenFileDialog();ofd.Filter= "All Files(*.*)|*.*";if(ofd.ShowDialog() == DialogResult.OK){this.listBox2.Items.Add(ofd.FileName);}}catch(Exception ex){ShowException(ex.Message);}}void BtnRemoveFileClick(object sender, EventArgs e){try{if(this.listBox2.SelectedItem != null){int index = this.listBox2.SelectedIndex;this.listBox2.Items.RemoveAt(index);}}catch(Exception ex){ShowException(ex.Message);}}void BtnCompressClick(object sender, EventArgs e){try{string archiveName = string.Empty;SaveFileDialog sfd = new SaveFileDialog();sfd.Filter = "ZIP File(*.zip)|*.zip|RAR File(*.rar)|*.rar";if( sfd.ShowDialog() == DialogResult.OK){archiveName = sfd.FileName;string[] fileFullNames = new string[this.listBox2.Items.Count];int i = 0;foreach(object o in this.listBox2.Items){fileFullNames[i++] = o.ToString();}compressor.FileCompressionStarted += delegate { this.label3.Text = "Start compressing...";};compressor.FileCompressionFinished += delegate { this.label3.Text = "Finish compressing.";};compressor.CompressFiles(archiveName,fileFullNames);ShowInformation("Compressiong Finished!");}}catch(Exception ex){ShowException(ex.Message);}}}}
【更多阅读】
- [原]C#实现将文本转换为图片
- [译]C# DirectShow编程手册及实例
- [原]Freeplot: MATLAB来帮你手动画图
- [原]Windows 7下用Android手机实现DLNA共享
- [译]C#检测程序是否已经运行并置顶
- [原]C#用firefox3.6下载yunfile的文件
- [原]Android NDK开发环境的搭建,无需Cygwin
- [原]Html2Pdf:C调用wkhtmltopdf的API来将Html转换为pdf文件
- [译]TIOBE 2012年10月份编程语言排行榜
- [原]pjCLibs:方便C语言编程而作的函数库
- C#:SevenZipSharp使用7z.dll来进行压缩与解压缩
- 使用7z完成文件压缩与解压缩
- 使用SevenZipSharp压缩、解压文件
- Java使用sevenzipjbind解压缩7z压缩包
- 使用JAVA进行ZIP格式的压缩与解压缩
- 命令行压缩解压缩一 7z
- 7、压缩与解压缩
- 利用7zip sdk进行数据流的压缩与解压缩
- 使用DotNetZip压缩与解压缩
- 使用ZipEntry压缩与解压缩
- 7z 命令行 进行单文件极限压缩与解压
- 压缩与解压缩(tar/7z/zip/rar)--Ubuntu小笔记
- Linux下使用Zlib压缩库,进行文件的压缩与解压缩 (一)
- tar、7z(7zip)压缩/解压缩指令的使用
- tar、7z(7zip)压缩/解压缩指令的使用
- 使用ASIHTTPRequest的ASIDataCompressor与ASIDataDecompressor进行gzip压缩与解压缩,出现的问题
- 压缩、解压缩.zip,.rar,.7z格式java工具类
- 在C#中使用J#运行时来压缩与解压缩
- 自写聊天工具,及建立Socket步骤详解
- WM_PAINT 和 WM_ERASEBKGND 消息的区别
- MyEclipse9下Maven开发Web工程的配置教程
- Oracle EBS订单的流程(Order->AR)
- Extjs 中的accordion
- C#:SevenZipSharp使用7z.dll来进行压缩与解压缩
- HDU 1007
- 访问布署在resin中的项目出现 java.net.UnknownHostException: .: .异常
- SDK基本的语句与操作——《c语言也能干大事》笔记
- java 常用弹出框
- Mysql,SqlServer,Oracle主键自动增长的设置
- IOS细节之虚拟键盘隐藏事件添加与删除bug
- SCADA--监控组态软件
- MACBOOK彻底删除OSX安装WIN7