ASP.NET利用WINRar实现在线解压缩文件

一、肯定是服务器必须装了winrar这个软件了。

二、创建Helper类,如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Diagnostics;
using System.IO;

namespace XXX.Common
{

    public class ZipHelper
    {
        public bool DeCompressRAR(string sourceFilePath, string destinationPath)
        {
            try
            {
                string SeverDir = @"C:\Program Files\WinRAR";//rar.exe的要目录 
                Process ProcessDecompression = new Process();
                ProcessDecompression.StartInfo.FileName = SeverDir + "\\rar.exe";
                Directory.CreateDirectory(destinationPath);
                ProcessDecompression.StartInfo.Arguments = " X " + sourceFilePath + " " + destinationPath;
                ProcessDecompression.Start();
                while (!ProcessDecompression.HasExited)
                {
                    //nothing to do here. 
                }
                return true;
            }
            catch (System.Exception)
            {
                return false;
            }
        } 
    }
}

三、直接调用就可以了,如下:

        public ActionResult jieya()
        {
            Common.ZipHelper zipHelper = new Common.ZipHelper();
            zipHelper.DeCompressRAR(@"d:\210.rar", @"d:\a\");
            return Json(message, JsonRequestBehavior.AllowGet);
        }

 

posted @ 2014-05-08 09:08  屌丝大叔的笔记  阅读(1168)  评论(0编辑  收藏  举报