asp.net compressed folder call Example: RAR ("e:/www.jb51.net/", "E:/www.jb51.net.rar");
asp.net uncompressed rar file Call Example: Unrar ("E:/www.jb51.net.rar", "e:/");
Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Diagnostics;
Namespace BLL
{
public class Cmdutil
{
///
Execute Cmd.exe command
///
Command text
Command output text
public static string Execommand (String commandtext)
{
Return Execommand (new string[] {commandtext});
}
///
Execute multiple Cmd.exe commands
///
Array of command text
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;
}
///
To start an external Windows application, hide the program interface
///
Application path name
True indicates success, 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, False indicates failure
public static bool StartApp (string appName, ProcessWindowStyle style)
{
Return StartApp (appName, null, style);
}
///
Start an external application, hide the program interface
///
Application path name
Startup parameters
True indicates success, False indicates failure
public static bool StartApp (string appName, String arguments)
{
Return StartApp (appName, arguments, Processwindowstyle.hidden);
}
///
Start an external application
///
Application path name
Startup parameters
Process window Mode
True indicates success, 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+ ");
}
}
}