123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /******************************************************************
- ** 文 件 名: winRAR.cs
- ** 创 建 人: wufs
- ** 创建日期: 2009/12/11 15:29:17
- ** 描 述: 使用winRar来对文件进行压缩处理
- ** 版 本: 1.0.0
- ** 修改描述:
- ** 修 改 人:
- ** 修改日期:
- ******************************************************************/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Diagnostics;
- using System.Configuration;
- namespace Bowin.Common
- {
- public class WinRAR
- {
- private static string _RarPath = ConfigurationManager.AppSettings["WinRARPath"];
- /// <summary>
- /// 把一个文件压缩(文件源删除)
- /// </summary>
- /// <param name="sourceFile"></param>
- /// <param name="RarFile"></param>
- /// <returns></returns>
- public static bool Rar(string sourceFile,string RarFile)
- {
- string DOSstr = "m -ep1 \"{0}\" \"{1}\"";
- DOSstr = string.Format(DOSstr,RarFile,sourceFile);
- return doRar(DOSstr);
- }
- /// <summary>
- /// 把一个文件按相对路径解压
- /// </summary>
- /// <param name="sourceFile"></param>
- /// <param name="unUrlPath"></param>
- /// <returns></returns>
- public static bool unRar(string sourceFile,string unUrlPath)
- {
- string DOSstr = "x \"{0}\" \"{1}\"";
- DOSstr = string.Format(DOSstr, sourceFile, unUrlPath);
- return doRar(DOSstr);
- }
- /// <summary>
- /// 接收操作winRar的命令
- /// eg.->Rar a file.rar file.txt
- /// 传入字符串:
- /// ->"a file.rar file.txt"
- /// </summary>
- /// <param name="DOSstr"></param>
- /// <returns></returns>
- public static bool doRar(string DOSstr)
- {
- bool ret = false;
- Process p = new Process();
- p.StartInfo.FileName = _RarPath;
- p.StartInfo.UseShellExecute = true;
- p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
- try
- {
- p.StartInfo.Arguments=DOSstr;
- p.Start();
- p.WaitForExit();
- p.Close();
-
- ret=true;
- }
- catch
- {
- p.Close();
- }
- return ret;
- }
- }
- }
|