您的位置:首页 > 编程语言 > ASP

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

2014-05-08 09:08 555 查看
一、肯定是服务器必须装了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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: