If RAR is installed on the serverProgramSo Asp.net can call RAR to compress and decompress files.
However, it should be noted that the web program cannot directly call the client program (unless ActiveX is used, ActiveX is almost deprecated ), therefore, to decompress a local file on a webpage, you must upload the file to the server and then call RAR compression on the server, similarly, to decompress the local rarfile, you can upload the file to the server and extract it.
This article describes howServerDirectory to decompress the file!
:
Front-endCode:
<%... @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> server extract clear moon http://blog.csdn.net/21aspnet/%3C/title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: button id = "button1" runat = "server" onclick = "button#click" text = "COMPRESSED"/>
<Asp: button id = "button2" runat = "server" onclick = "button2_click" text = "decompress"/> </div>
</Form>
</Body>
</Html>
Background code:
Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. IO;
Using system. runtime. interopservices;
Using Microsoft. Win32;
Using system. diagnostics;
Public partial class _ default: system. Web. UI. Page
...{
Protected void page_load (Object sender, eventargs E)
...{
// Clear moon http://blog.csdn.net/21aspnet/
}
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" + "1.rar" + "" + "C: \ 1 \ 1.txt ";
The_startinfo = new processstartinfo ();
The_startinfo.filename = the_rar;
The_startinfo.arguments = the_info;
The_startinfo.windowstyle = processwindowstyle. hidden;
The_startinfo.workingdirectory = "C: \ 1"; // gets or sets the initial directory of the process to be started.
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" + "1.rar" + "" + "C: \ 1 ";
The_startinfo = new processstartinfo ();
The_startinfo.filename = the_rar;
The_startinfo.arguments = the_info;
The_startinfo.windowstyle = processwindowstyle. hidden;
The_process = new process ();
The_process.startinfo = the_startinfo;
The_process.start ();
Response. Write ("decompressed ");
}
Catch (exception ex)
...{
Response. Write (ex. tostring ());
}
}
}
Server Directory:
Client decompression workarounds: