Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.web.ui.webcontrols;using system.diagnostics;using System.io;public partial class zip:system.web.ui.page{prot ected void Page_Load (object sender, EventArgs e) {}//compressed file protected void Button1_Click (object sender, Eventa RGS e) {ProcessStartInfo startinfo = new ProcessStartInfo (); Process process = new process (); String rarname = "1.rar"; Compressed file name string path = @ "C:\images"; Package folder to compress string Rarpath = @ "C:\zip"; Compressed after storing folder string rarexe = @ "C:\Program Files\winrar\winrar.exe"; WinRAR Install location try {//compress command, equivalent to the right-click on the folder (path) to be compressed->winrar-> add to the compressed file, enter the compressed filename (rarname) string cmd = string. Format ("a {0} {1}-R", Rarname, Path); StartInfo. FileName = Rarexe; StartInfo. Arguments = cmd; Sets the command parameter StartInfo. WindowStyle = Processwindowstyle.hidden; Hides the WinRAR window startinfo. WorkingDirectory = Rarpath; Process. StartInfo = StartInfo; Process. Start (); Process. WaitForExit (); Waits indefinitely for the process to Winrar.exe exit if (process. hasexited) {MscL. Jshelper.alert ("Compression succeeded! ", page); }} catch (Exception ex) {MSCL. Jshelper.alert (ex. Message, Page); } finally {process. Dispose (); Process. Close (); }}//extract file protected void button2_click (object sender, EventArgs e) {ProcessStartInfo Startinf o = new ProcessStartInfo (); Process process = new process (); String rarname = "1.rar"; The. rar file name (including the suffix) that will be decompressed string path = @ "C:\images1"; File decompression Path (absolute) string rarpath = @ "C:\zip"; The storage directory (absolute path) of the. rar file that will be decompressed string rarexe = @ "C:\Program Files\winrar\winrar. exe "; WinRAR Install location try {//unzip command, equivalent to right-click on the file to be compressed (rarname)->winrar-> extract to the current folder, string cmd = String. Format ("x {0} {1}-y", rarname, Path); StartInfo. FileName = Rarexe; StartInfo. Arguments = cmd; Sets the command parameter StartInfo. WindowStyle = Processwindowstyle.hidden; Hides the WinRAR window startinfo. WorkingDirectory = Rarpath; Process. StartInfo = StartInfo; Process. Start (); Process. WaitForExit (); Waits indefinitely for the process to Winrar.exe exit if (process. hasexited) {MscL. Jshelper.alert ("Unzip successfully!") ", page); }} catch (Exception ex) {MSCL. Jshelper.alert (ex. Message, Page); } finally {process. Dispose (); Process. Close (); } }}
C # uses the WinRAR command to compress and decompress (pro-test pass)