c#直接解压缩 winrar文件

最近在项目中需要读取winrar文件,为解决此问题,查找了一下百度,发现很多的解决方案是直接调用winrar程序,解压缩后再读取文件,关于这个方案的代码如下:

public string unRAR(string unRarPatch,string rarPatch,string rarName)
     {
        String the_rar;
        RegistryKey the_Reg;
        Object the_Obj;
        String the_Info;
        ProcessStartInfo the_StartInfo;
        Process the_Process;
        
try
         {
            the_Reg 
= Registry.ClassesRoot.OpenSubKey(@"ApplicationsWinRAR.exeShellOpenCommand");
            the_Obj 
= the_Reg.GetValue("");
            the_rar 
= the_Obj.ToString();
            the_Reg.Close();
            the_rar 
= the_rar.Substring(1, the_rar.Length - 7);
            Directory.CreateDirectory(Server.MapPath(unRarPatch));
            the_Info 
= "e   " + rarName + "  " + Server.MapPath(unRarPatch) + " -y";
            the_StartInfo 
= new ProcessStartInfo();
            the_StartInfo.FileName 
= the_rar;
            the_StartInfo.Arguments 
= the_Info;
            the_StartInfo.WindowStyle 
= ProcessWindowStyle.Hidden;
            the_StartInfo.WorkingDirectory 
= Server.MapPath(rarPatch);//获取压缩包路径
            the_Process = new Process();
            the_Process.StartInfo 
= the_StartInfo;
            the_Process.Start();
            the_Process.WaitForExit();
            the_Process.Close();
        }
        
catch (Exception ex)
         {
            
throw ex;
        }
        
return Server.MapPath(unRarPatch);
    }


我也直接用这种方法实现了该功能,但是在实际中,还是遇到了问题,比如对于解压缩路径中带有空格的,则解压缩失败,而且由于版本不同,对于不同的电脑上也会产生不同的结果。没办法,只好再找别的方案,直接打开winrar的程序,在他的帮助文档里找到了winrar程序对于解压缩提供了一个免费的工具,以及部分源代码,部分的 UNRAR 原始码可在下列网址获得 http://www.rarlab.com,

后来在http://www.rarlab.com/rar_add.htm 网页上找到了该源码,编译后,按照自己需要的接口,包装一层,问题解决 ,而且还可以查看rar文件的内容,解压进度显示等都可以实现。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值