asp.net中调用winrar实现压缩解压缩的代码

时间:2023-07-18 14:30:30 

asp.net压缩文件夹调用示例:rar("e:/www.aspxhome/", "e:/www.aspxhome.rar");
asp.net解压缩rar文件调用示例:unrar("e:/www.aspxhome.rar", "e:/");


using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace BLL
{
public class CmdUtil
{
///
/// 执行cmd.exe命令
///
///命令文本
/// 命令输出文本
public static string ExeCommand(string commandText)
{
return ExeCommand(new string[] { commandText });
}
///
/// 执行多条cmd.exe命令
///
///命令文本数组
/// 命令输出文本
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;
}
///
/// 启动外部Windows应用程序,隐藏程序界面
///
///应用程序路径名称
/// true表示成功,false表示失败
public static bool StartApp(string appName)
{
return StartApp(appName, ProcessWindowStyle.Hidden);
}
///
/// 启动外部应用程序
///
///应用程序路径名称
///进程窗口模式
/// true表示成功,false表示失败
public static bool StartApp(string appName, ProcessWindowStyle style)
{
return StartApp(appName, null, style);
}
///
/// 启动外部应用程序,隐藏程序界面
///
///应用程序路径名称
///启动参数
/// true表示成功,false表示失败
public static bool StartApp(string appName, string arguments)
{
return StartApp(appName, arguments, ProcessWindowStyle.Hidden);
}
///
/// 启动外部应用程序
///
///应用程序路径名称
///启动参数
///进程窗口模式
/// true表示成功,false表示失败
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+");
}
}
}


标签:asp.net,压缩,解压缩,winrar
0
投稿

猜你喜欢

  • 网站更新短平快

    2007-02-03 11:39:00
  • pjblog3相关日志功能(支持生成静态模式)

    2008-11-20 13:41:00
  • 网页广告 Banner 设计图文手册

    2007-10-18 19:56:00
  • Firefox 3.5 新增加的支持(整理)

    2009-08-01 12:51:00
  • CSS网页布局开发时的常见问题小结

    2009-08-13 12:17:00
  • access改mdb为asp所带来的灾难 附mdb防下载方法

    2011-03-03 11:07:00
  • CSS sprites图片拼合生成器

    2007-10-15 12:25:00
  • Oracle SQL性能优化系列学习一

    2010-07-26 13:14:00
  • 根据表名和索引获取需要的列名的存储过程

    2011-09-30 11:54:42
  • Go语言题解LeetCode35搜索插入位置示例详解

    2023-07-16 17:17:00
  • ASP 调用带参数输出的COM接口

    2011-03-17 10:59:00
  • ACCESS入门教程:初识Access 2000

    2008-01-03 19:42:00
  • XML十项特点

    2008-04-05 13:49:00
  • ASP常用函数:IsBlank()

    2008-09-28 13:21:00
  • ASP Cookies操作的详细介绍与实例代码

    2011-03-10 10:53:00
  • 网友分享:Oracle数据库开发技术经验浅谈

    2009-04-22 13:11:00
  • ASP实现全站的301跳转

    2010-03-27 21:45:00
  • 如何用Axure制作Tab页签

    2009-02-08 17:53:00
  • ie7.0浏览器 兼容问题苦煞网站设计者

    2007-08-08 17:11:00
  • HTML中事件触发列表与解说

    2007-10-22 12:50:00
  • asp之家 网络编程 m.aspxhome.com