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 {protected void Page_Load (object sender, EventArgs e) {} Compressed file protected void Button1_Click (object sender, EventArgs e) {ProcessStartInfo startinfo = new Proces
Sstartinfo ();;
Process process = new process (); String rarname = "1.rar"; Compressed filename String path = @ "C:\images"; To compress the packaged folder string Rarpath = @ "C:\zip"; Storage folder after compression Rarexe = @ "C:\Program Files\winrar\winrar.exe";
WinRAR the install location try {//compression command, which is equivalent to the right key on the folder (path) to be compressed->winrar-> add to the compressed file-> input 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 (); Wait indefinitely for the process to exit the IF (Winrar.exe). 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 St
Artinfo = new ProcessStartInfo ();;
Process process = new process (); String rarname = "1.rar"; The. rar filename (including suffix) that will be decompressed string path = @ "C:\images1"; File decompression Path (absolute) string rarpath = @ "C:\zip"; Storage of. rar files that will be decompressedDirectory (absolute path) string rarexe = @ "C:\Program Files\winrar\winrar.exe"; WinRAR Install location try {//extract command, equivalent to compressed file (Rarname) on the point right click->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 (); Wait indefinitely for the process to exit the IF (Winrar.exe). hasexited) {MscL. Jshelper.alert ("decompression succeeded.")
", Page); } catch (Exception ex) {MSCL. Jshelper.alert (ex.
message, Page); finally {process.
Dispose (); Process.
Close (); }
}
}