The example in this article describes how C # uses the WinRAR command for compression and decompression operations. Share to everyone for your reference, specific as follows:
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 ProcessStartInfo ();;
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 ZIP file name (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 ("Compact success!")
", 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 startinfo = new Process
StartInfo ();;
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"; The storage directory (absolute path) of the. rar file that will be uncompressed, string rarexe = @ "C:\Program Files\winrar\winrar.exe"; WinRAR Install location try {//extract command, equivalent to compressed file (Rarname) on the Point right button->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 success!")
", Page); } catch (Exception ex) {MSCL. Jshelper.alert (ex.
message, Page); finally {process.
Dispose (); Process.
Close ();
}
}
}
Read more about C # Interested readers can view the site topics: "C # Common control usage Tutorial", "WinForm Control Usage Summary", "C # Data structure and algorithm tutorial", "C # object-oriented Program design Introductory Course" and "C # programming Thread Usage Skill Summary"
I hope this article will help you with C # programming.