Asp.net automatically decompress the rarfile uploaded

Source: Internet
Author: User
Using System;
Using System. IO;
Using System. Diagnostics;
Using System. Collections;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Web. Security;
Using System. Web;
Using System. Web. SessionState;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. HtmlControls;
Namespace WebLayer
{
/** // <Summary>
/// Summary of WebForm1.
/// </Summary>
Public class WebForm1: System. Web. UI. Page
{
Protected System. Web. UI. WebControls. Button Button1;
Protected system. Web. UI. htmlcontrols. htmlinputfile myfile;

Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
}

Code generated by web form designer # code generated by region web Form Designer
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}

/** // <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void InitializeComponent ()
{
This. Button1.Click + = new System. EventHandler (this. button#click );
This. Load + = new System. EventHandler (this. Page_Load );

}
# Endregion

Private void button#click (object sender, System. EventArgs e)
{
String path = @ "C: \" + myfile. PostedFile. FileName. Substring (myfile. PostedFile. FileName. LastIndexOf ("\\"));
Myfile. PostedFile. SaveAs (path );
Response. Write ("File Uploaded successfully:" + path );
// Response. End ();
// Place user code here to initialize the page
Process p = new Process ();
P. StartInfo. UseShellExecute = false;
P. StartInfo. RedirectStandardInput = true;
P. StartInfo. RedirectStandardOutput = true;
P. StartInfo. RedirectStandardError = true;
P. StartInfo. CreateNoWindow = true;
P. StartInfo. FileName = "cmd.exe ";
P. Close ();
// Decompress the rarfile
String ServerDir = @ "C: \ Program Files \ WinRAR"; // rar path
System. Diagnostics. Process process1 = new process ();
Process1.startinfo. filename = serverdir + "\ rar.exe ";
Directory. createdirectory (path + ". Files"); // create an extract folder
Process1.startinfo. Arguments = "X-inul-y" + path + "" + path + ". Files ";
Process1.start (); // Extract
While (! Process1.hasexited) // wait until the decompression is completed
{
}
// File. Delete (PATH); // Delete the rarfile
}
}
}

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.