asp.net调用压缩软件对文件进行压缩与解压缩的代码
Admin
|
2009-4-25 18:41:28
|
TrackRecord:
1252
Times | Tag标签:asp.net
打印本页
您当前所处的位置是:〖首页〗→【文章页】
本站共有16个图文教程栏目,请用心拜读!
本站提供经典的Excel公式函数实例,Word排版技巧,PPT教程;同时更兼有Flash,PowerPoint,数据库等技术文章。
前提条件:需要服务器安装WinRar,并且把Rar.exe拷贝到网站根目录。
asp.net压缩文件夹调用示例:rar("D:/www.dzwebs.net/", "e:/www.dzwebs.net.rar");
asp.net解压缩rar文件调用示例:unrar("D:/www.dzwebs.net.rar", "D:/");
代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace BLL
{
public class CmdUtil
{
public static string ExeCommand(string commandText)
{
return ExeCommand(new string[] { commandText });
}
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;
}
public static bool StartApp(string appName)
{
return StartApp(appName, ProcessWindowStyle.Hidden);
}
public static bool StartApp(string appName, ProcessWindowStyle style)
{
return StartApp(appName, null, style);
}
public static bool StartApp(string appName, string arguments)
{
return StartApp(appName, arguments, ProcessWindowStyle.Hidden);
}
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+");
}
}
}
会员评论列表:

正在加载数据,请稍后……
针对本篇文章或本站,请您发表个人的建议或批评!