C # Implementation of compression and decompression operations using the WinRAR command _c# tutorial

Source: Internet
Author: User
Tags rar zip

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.