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 + ");
}
}
}