首页 新闻 会员 周边

急……急……C#压缩文件夹 在线等

0
悬赏园豆:20 [已解决问题] 解决于 2010-04-23 09:05

C#压缩文件夹

自由呼吸的主页 自由呼吸 | 初学一级 | 园豆:8
提问于:2010-04-19 12:41
< >
分享
最佳答案
0

这篇文章有详细的介绍和源码下载:http://kb.cnblogs.com/a/884095/

Astar | 高人七级 |园豆:40805 | 2010-04-19 13:28
都不错 谢谢大家
自由呼吸 | 园豆:8 (初学一级) | 2010-04-23 09:06
其他回答(2)
0

/// <summary>
        /// 压缩文件夹
        /// </summary>
        /// <param name="DirectoryName"></param>
        /// <param name="ZipFileName"></param>
        public static void Zip_Directory(string DirectoryName, string ZipFileName, string SavePath)
        {
            //压缩
            String myRar;
            RegistryKey myReg;
            Object myObj;
            String myInfo;
            ProcessStartInfo myStartInfo;
            Process myProcess;
            try
            {
                myReg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\Shell\Open\Command");
                myObj = myReg.GetValue("");
                myRar = myObj.ToString();
                myReg.Close();
                myRar = myRar.Substring(1, myRar.Length - 7);
                //rar命令参数
                myInfo = "a  -r  -ep1 " + SavePath + "\\" + ZipFileName + " " + DirectoryName;//a-压缩 -r -ep1文件夹内的全部文件和文件夹加入到压缩文件 压缩文件保存地址 要压缩的目录
                myStartInfo = new ProcessStartInfo();
                myStartInfo.FileName = myRar;
                myStartInfo.Arguments = myInfo;
                myStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                myStartInfo.WorkingDirectory = DirectoryName;//获取或设置要启动的进程的初始目录。
                myProcess = new Process();
                myProcess.StartInfo = myStartInfo;
                myProcess.Start();
            }
            catch { }
        }

调用WinRar进行压缩

需要引用的命名空间

using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Diagnostics;

收获园豆:20
ミ蓝色の雨っ | 园豆:230 (菜鸟二级) | 2010-04-19 13:24
不错
支持(0) 反对(0) 自由呼吸 | 园豆:8 (初学一级) | 2010-04-23 09:05
0

使用开源库 SharpZipLib 吧,不需要 WinRAR 也可以进行压缩、解压缩。

下面是代码示例:

http://www.cnblogs.com/bobofsj11/archive/2008/07/03/1234679.html

冠军 | 园豆:886 (小虾三级) | 2010-04-19 21:35
不错
支持(0) 反对(0) 自由呼吸 | 园豆:8 (初学一级) | 2010-04-23 09:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册