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 directory to be compressed string Rarpath = @ "C:\zip"; Compressed after storing directory string rarexe = @ "C:\Program Files\winrar\winrar.exe"; WinRAR Install location try {//compress command, equivalent to right-click on the directory to be Compressed (path)->winrar-> join to the compressed file, enter the compressed file name (rarname) string cmd = string. Format ("a {0} {1}-R", Rarname, Path); StartInfo. FileName = Rarexe; StartInfo. Arguments = cmd; Sets the number of command parameters StartInfo. WindowStyle = Processwindowstyle.hidden; Hides the WinRAR form 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 (containing 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 directory string cmd = String. Format ("x {0} {1}-y", rarname, Path); StartInfo. FileName = Rarexe; StartInfo. Arguments = cmd; Sets the number of command parameters StartInfo. WindowStyle = Processwindowstyle.hidden; Hides the WinRAR form 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