Call winrar command line mode to compress and decompress the file

Source: Internet
Author: User

Protected void button#click (object sender, EventArgs e)
{
// Compression
String the_rar;
RegistryKey the_Reg;
Object the_Obj;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
Try
{
The_Reg = Registry. ClassesRoot. OpenSubKey (@ "Applications \ WinRAR.exe \ Shell \ Open \ Command ");
The_Obj = the_Reg.GetValue ("");
The_rar = the_Obj.ToString ();
The_Reg.Close ();
The_rar = the_rar.Substring (1, the_rar.Length-7 );
The_Info = "a-r-ep1" + "a.rar" + @ "1 \*";
The_StartInfo = new ProcessStartInfo ();
The_StartInfo.FileName = the_rar;
The_StartInfo.Arguments = the_Info;
The_StartInfo.WindowStyle = ProcessWindowStyle. Hidden;
The_StartInfo.WorkingDirectory = @ "C: \ rar"; // The initial directory of the process.
//
The_Process = new Process ();
The_Process.StartInfo = the_StartInfo;
The_Process.Start ();
Response. Write ("compressed successfully ");
}
Catch (Exception ex)
{
Response. Write (ex. ToString ());
}
}
Protected void Button2_Click (object sender, EventArgs e)
{
// Extract
String the_rar;
RegistryKey the_Reg;
Object the_Obj;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
Try
{
The_Reg = Registry. ClassesRoot. OpenSubKey (@ "Applications \ WinRar.exe \ Shell \ Open \ Command ");
The_Obj = the_Reg.GetValue ("");
The_rar = the_Obj.ToString ();
The_Reg.Close ();
The_rar = the_rar.Substring (1, the_rar.Length-7 );
The_Info = @ "x" + @ "a.rar" + "" + @ "\";
The_StartInfo = new ProcessStartInfo ();
The_StartInfo.FileName = the_rar;
The_StartInfo.Arguments = the_Info;
The_StartInfo.WindowStyle = ProcessWindowStyle. Hidden;
The_StartInfo.WorkingDirectory = @ "C: \ rar"; // gets or sets the initial directory of the process to be started.
The_Process = new Process ();
The_Process.StartInfo = the_StartInfo;
The_Process.Start ();

While (! The_Process.HasExited) // wait until the decompression is completed
{
}
// File. Delete (filePath + fileName );

Response. Write (@ "decompressed ");
}
Catch (Exception ex)
{
Response. Write (ex. ToString ());
}
}

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.