弟弟我不太懂,我想压缩整合多个文件,怎么用C#来实现调用rar压缩?

解决方案 »

  1.   

    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("压缩文件不存在,请先压缩文件。");
            }
        }
    }
      

  2.   

    c#里面有 GZipStream 的。
    可以试试。