Use WinRAR in Asp.net to decompress and decompress the code

Source: Internet
Author: User

Asp.net compressed folder call example: RAR ("E:/www.jb51.net/", "E:/www.jb51.net.rar ");
Example of calling Asp.net to decompress the rarfile: unrar ("E:/www.jb51.net.rar", "E :/");

CopyCode The Code is as follows: using system;
Using system. Collections. Generic;
Using system. text;
Using system. diagnostics;

Namespace BLL
{
Public class cmdutil
{
///
/// Execute the cmd.exe command
///
/// Command text
/// Command output text
Public static string execommand (string commandtext)
{
Return execommand (New String [] {commandtext });
}
///
/// Execute multiple cmd.exe commands
///
/// Command text Array
/// Command output text
Public static string execommand (string [] commandtexts)
{
PROCESS p = new process ();
P. startinfo. filename = "cmd.exe ";
P. startinfo. useshellexecute = false;
P. startinfo. redirectstandardinput = true;
P. startinfo. redirectstandardoutput = true;
P. startinfo. redirectstandarderror = true;
P. startinfo. createnowindow = true;
String stroutput = NULL;
Try
{
P. Start ();
Foreach (string item in commandtexts)
{
P. standardinput. writeline (item );
}
P. standardinput. writeline ("exit ");
Stroutput = P. standardoutput. readtoend ();
// Stroutput = encoding. utf8.getstring (encoding. Default. getbytes (stroutput ));
P. waitforexit ();
P. Close ();
}
Catch (exception E)
{
Stroutput = E. message;
}
Return stroutput;
}
///
/// Start an external Windows Application Program , Hide the Program Interface
///
/// Application Path Name
/// True indicates success, and false indicates failure
Public static bool Startapp (string appname)
{
Return Startapp (appname, processwindowstyle. Hidden );
}
///
/// Start an External Application
///
/// Application Path Name
/// Process window mode
/// True indicates success, and false indicates failure
Public static bool Startapp (string appname, processwindowstyle style)
{
Return Startapp (appname, null, style );
}
///
/// Start an external application to hide the Program Interface
///
/// Application Path Name
/// Start Parameters
/// True indicates success, and false indicates failure
Public static bool Startapp (string appname, string arguments)
{
Return Startapp (appname, arguments, processwindowstyle. Hidden );
}
///
/// Start an External Application
///
/// Application Path Name
/// Start Parameters
/// Process window mode
/// True indicates success, and false indicates failure
Public static bool Startapp (string appname, string arguments, processwindowstyle style)
{
Bool blnrst = false;
PROCESS p = new process ();
P. startinfo. filename = appname; // EXE, bat and so on
P. startinfo. windowstyle = style;
P. startinfo. Arguments = arguments;
Try
{
P. Start ();
P. waitforexit ();
P. Close ();
Blnrst = true;
}
Catch
{
}
Return blnrst;
}

Public static void RAR (string S, string D)
{
Execommand (system. Web. httpcontext. Current. server. mappath ("~ /Rar.exe ") +" A \ "" + D + "\" \ "" + S + "\"-EP1 ");
}

Public static void unrar (string S, string D)
{
Execommand (system. Web. httpcontext. Current. server. mappath ("~ /Rar.exe ") +" x \ "" + S + "\" \ "" + D + "\"-O + ");
}

}
}

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.