基本信息
源码名称:C# 文件压缩 例子源码
源码大小:0.16M
文件格式:.rar
开发语言:C#
更新时间:2017-11-28
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
c#文件压缩,代码可以修改使用
c#文件压缩,代码可以修改使用
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Checksums;
using System.IO;
namespace Zip
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void ZipFilenew(string strFileFolder, string strZip)
{
if (strFileFolder[strFileFolder.Length - 1] != Path.DirectorySeparatorChar)
strFileFolder = Path.DirectorySeparatorChar;
ZipOutputStream s = new ZipOutputStream(File.Create(strZip));
s.SetLevel(6); // 0 - store only to 9 - means best compression
zip(strFileFolder, strZip, s);
s.Finish();
s.Close();
}
private void zip(string strFile, string StoreFile, ZipOutputStream s)
{
if (strFile[strFile.Length - 1] != Path.DirectorySeparatorChar)
strFile = Path.DirectorySeparatorChar;
Crc32 crc = new Crc32();
string[] filenames = Directory.GetFileSystemEntries(strFile);
foreach (string file in filenames)
{
if (Directory.Exists(file))
{
zip(file,StoreFile, s);
}
else
{
//打开压缩文件,开始压缩
FileStream fs = File.OpenRead(file);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
string tempfile = file.Substring(StoreFile.LastIndexOf("\\") 1);
ZipEntry entry = new ZipEntry(tempfile);
entry.DateTime = DateTime.Now;
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
if (Directory.Exists(textBox1.Text.ToString().Trim()))
{
ZipFilenew(textBox1.Text.ToString().Trim(), "d:\\e.zip");
}
else
{
MessageBox.Show("非法的路径");
}
}
private static void RunEXE(string exeFileName, string arguments)
{
//声明一个程序信息类
System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
//设置外部程序名
Info.FileName = exeFileName;
//设置外部程序的启动参数(命令行参数)
Info.Arguments = arguments;
//声明一个程序类
System.Diagnostics.Process Proc;
try
{
//启动外部程序
Proc = System.Diagnostics.Process.Start(Info);
}
catch
{
MessageBox.Show("系统找不到指定的程序文件。");
return;
}
//等待完成
Proc.WaitForExit();
}
private void button2_Click(object sender, EventArgs e)
{
RunEXE(textBox2.Text.ToString().Trim(), "a -ep d:\\20071112.rar G:\\Dev\\SQLServer2005SP1-KB913090-x86-CHS.exe");
}
}
}