饮歌长啸
/// <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;