C # uses the WinRAR command to compress and decompress

Source: Internet
Author: User
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 ();      }   
    }
} 

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.