// 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)