asp.net to invoke winrar to implement compression decompression code _ Practical Skills

Source: Internet
Author: User

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

}
}

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.