如何实现文件压缩 弟弟我不太懂,我想压缩整合多个文件,怎么用C#来实现调用rar压缩? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Lib;using System.IO;public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } /// <summary> /// 压缩 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnCompress_Click(object sender, EventArgs e) { String path = Server.MapPath("~/Files/"); // 检查文件是否存在 if (File.Exists(path + "第2章 使用数据库.pdf")) { FileInfo fi1 = new FileInfo(path + "第2章 使用数据库.pdf"); FileInfo fi2 = new FileInfo(path + "第3章 使用数据绑定和DataSet.pdf"); FileInfo fi3 = new FileInfo(path + "第4章 SQL Server XML的功能.pdf"); FileInfo fi4 = new FileInfo(path + "第5章 XML编程.pdf"); List<FileInfo> fileList = new List<FileInfo>(); fileList.Add(fi1); fileList.Add(fi2); fileList.Add(fi3); fileList.Add(fi4); // 调用方法 string targetZipFilePath = Server.MapPath("~/ZipFile/") + "Book.zip";// 扩展名可随意 Lib.FileCompression.Compress(fileList, targetZipFilePath, 5, 5); Response.Write("文件压缩成功,请在ZipFile文件夹查看。"); } else { Response.Write("被压缩文件不存在,请先解压文件。"); } } /// <summary> /// 解压缩 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDecompress_Click(object sender, EventArgs e) { string zipFilePath = Server.MapPath("~/ZipFile/") + "Book.zip";// if (File.Exists(zipFilePath)) { string targetPath = Server.MapPath("~/Files/"); Lib.FileCompression.Decompress(zipFilePath, targetPath); //// 解压后要删除zip文件 //File.Delete(zipFilePath); Response.Write("文件解压成功,请在Files文件夹查看。"); } else { Response.Write("压缩文件不存在,请先压缩文件。"); } }} c#里面有 GZipStream 的。可以试试。 asp怎么判断asp:checkbox是否被选中 关于定时器的问题,如定义每1秒执行一函数A,但这个函数A在1秒内可能执行不完,需要5秒 动态实例化 怎样把嵌入IE的word文档保存到数据库服务器 如何把ACCESS传到水晶报表的日期类型的时间部分显示出来? 采用C#开发一个已知网卡地址停止其上网 我在C#中用存储过程在sqlsever中创建的表,不能访问?急,在线等 windowsphone socket聊天 这个函数怎么理解?? C#曾么样呀? 如何获取某路径下的文件的文件名? 老是报错说当前上下文找不到dt
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Lib;
using System.IO;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
/// <summary>
/// 压缩
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnCompress_Click(object sender, EventArgs e)
{
String path = Server.MapPath("~/Files/");
// 检查文件是否存在
if (File.Exists(path + "第2章 使用数据库.pdf"))
{
FileInfo fi1 = new FileInfo(path + "第2章 使用数据库.pdf");
FileInfo fi2 = new FileInfo(path + "第3章 使用数据绑定和DataSet.pdf");
FileInfo fi3 = new FileInfo(path + "第4章 SQL Server XML的功能.pdf");
FileInfo fi4 = new FileInfo(path + "第5章 XML编程.pdf");
List<FileInfo> fileList = new List<FileInfo>();
fileList.Add(fi1);
fileList.Add(fi2);
fileList.Add(fi3);
fileList.Add(fi4);
// 调用方法
string targetZipFilePath = Server.MapPath("~/ZipFile/") + "Book.zip";// 扩展名可随意
Lib.FileCompression.Compress(fileList, targetZipFilePath, 5, 5);
Response.Write("文件压缩成功,请在ZipFile文件夹查看。");
}
else
{
Response.Write("被压缩文件不存在,请先解压文件。");
} } /// <summary>
/// 解压缩
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDecompress_Click(object sender, EventArgs e)
{
string zipFilePath = Server.MapPath("~/ZipFile/") + "Book.zip";//
if (File.Exists(zipFilePath))
{
string targetPath = Server.MapPath("~/Files/");
Lib.FileCompression.Decompress(zipFilePath, targetPath);
//// 解压后要删除zip文件
//File.Delete(zipFilePath);
Response.Write("文件解压成功,请在Files文件夹查看。");
}
else
{
Response.Write("压缩文件不存在,请先压缩文件。");
}
}
}
可以试试。