Asp.net calls RAR to compress and decompress files

Source: Internet
Author: User

// Compression
Protected void btny_click (Object sender, eventargs E)
{
String RAR;
Registrykey reg;
String ARGs;
Processstartinfo procstart;
Process process;
Try
{
Reg = registry. classesroot. opensubkey (@ "applications \ winrar.exe \ shell \ open \ command ");
RAR = reg. getvalue (""). tostring (); // obtain the Registry RAR installation path
Reg. Close ();
RAR = RAR. substring (1, rar. Length-7); // obtain the RAR installation path
ARGs = "a-inul-y g :\\ temp.rar g :\\ 1.txt"; // here is the RAR compression Command Format (you can also expand it yourself)
Procstart = new processstartinfo ();
Procstart. filename = RAR;
Procstart. Arguments = ARGs; // Parameter
Procstart. windowstyle = processwindowstyle. Hidden; // window status
Procstart. workingdirectory = server. mappath (""); // gets or sets the initial directory of the process to be started.
Process = new process ();
Process. startinfo = procstart;
Process. Start ();
Response. Write ("<SCRIPT> alert ('compressed successfully') </SCRIPT> ");
}
Catch (exception ex)
{
Response. Write (ex. tostring ());
}
}
// Extract
Protected void btnj_click (Object sender, eventargs E)
{
String RAR;
Registrykey reg;
String ARGs;
Processstartinfo startinfo;
Process process;
Try
{
Reg = registry. classesroot. opensubkey (@ "applications \ winrar.exe \ shell \ open \ command ");
RAR = reg. getvalue (""). tostring ();
Reg. Close ();
RAR = RAR. substring (1, rar. Length-7 );
ARGs = "x e :\\ temp.rar e :\\";
Startinfo = new processstartinfo ();
Startinfo. filename = RAR;
Startinfo. Arguments = ARGs;
Startinfo. windowstyle = processwindowstyle. hidden;
Process = new process ();
Process. startinfo = startinfo;
Process. Start ();
Response. Write ("<SCRIPT> alert ('decompressed successfully') </SCRIPT> ");
}
Catch (exception ex)
{
Response. Write (ex. tostring ());
}
}

For example, pack all the East-West packages in E: \ WEB \ directory as 1.rar and put it in the E: \ WEB \ directory for download.
"C: \ Program Files \ WinRAR \ rar.exe" a-k-r-s-M1 E: \ WEB \ 1.rar E: \ WEB \
Parameter description:
A. Add the file to the compressed file.
-K: Lock the compressed file
-S Generates solid archives to increase the compression ratio.
-R includes subdirectories
-M1 sets the compression ratio.
-When you add M0 storage to a compressed file, the file is not compressed.
-M1: the fastest way to use (low compression)
-M2: Fast Compression
-Standard (default) compression mode for M3
-M4: better compression mode (better compression, but slow)
-M5 is best to use the maximum compression method (the best compression, but the slowest)

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.