c#调用winrar解压缩文件代码分享

 更新时间:2013年12月09日 09:28:17   作者:  
这篇文章主要介绍了c#调用winrar解压缩文件的方法,大家参考使用吧

复制代码 代码如下:

using Microsoft.Win32;
using System.Diagnostics;
压缩
string the_rar;
RegistryKey the_Reg;
object the_Obj;
string the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\Shell\Open\Command");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
the_Info = " a " + " test.rar " + " " + @"C:\test\test.txt";
the_StartInfo = new ProcessStartInfo();


the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = @"C:\test\";
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
Response.Write("<script>alert('Zip Successfully');</script>");
}
catch
{
Response.Write("<script>alert('Zip Failed.')</script>");
}

解压缩

复制代码 代码如下:

string the_rar;
RegistryKey the_Reg;
object the_Obj;
string the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\Shell\Open\Command");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
the_Info = " X " + " test.rar " + @"C:\test\";
the_StartInfo = new ProcessStartInfo();


the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = @"C:\test\";
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
Response.Write("<script>alert('UnZip Successfully');</script>");
}
catch
{
Response.Write("<script>alert('UnZip Failed.')</script>");
}

相关文章

  • Unity制作自定义字体的两种方法

    Unity制作自定义字体的两种方法

    这篇文章主要为大家详细介绍了Unity制作自定义字体的两种方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2020-12-12
  • C#中DateTime函数的详细用法

    C#中DateTime函数的详细用法

    这篇文章介绍了C#中DateTime函数的详细用法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-06-06
  • C#之如何实现多个子窗体切换效果

    C#之如何实现多个子窗体切换效果

    这篇文章主要介绍了C#之如何实现多个子窗体切换的效果,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-07-07
  • C# Entity Framework中的IQueryable和IQueryProvider详解

    C# Entity Framework中的IQueryable和IQueryProvider详解

    这篇文章主要介绍了C# Entity Framework中的IQueryable和IQueryProvider详解,本文使用实例分析这两个接口的内部实现,需要的朋友可以参考下
    2015-01-01
  • 基于WPF实现验证码控件

    基于WPF实现验证码控件

    这篇文章主要介绍了如何利用WPF实现一个简单的验证码控件,文中的示例代码讲解详细,对我们学习或工作有一定帮助,需要的可以参考一下
    2022-08-08
  • C#关于Task.Yeild()函数的讨论

    C#关于Task.Yeild()函数的讨论

    这篇文章主要介绍了C#中关于Task.Yeild()函数的相关资料,文中讲解非常细致,帮助大家更好的理解和学习,感兴趣的朋友可以了解下
    2020-07-07
  • c#的dllimport使用方法详解

    c#的dllimport使用方法详解

    DllImport是System.Runtime.InteropServices命名空间下的一个属性类,其功能是提供从非托管DLL导出的函数的必要调用信息
    2014-01-01
  • 关于WPF异步MVVM等待窗体的介绍

    关于WPF异步MVVM等待窗体的介绍

    本篇文章小编将为大家介绍,关于WPF异步MVVM等待窗体的介绍,需要的朋友参考下
    2013-04-04
  • Unity 通过LineRenderer绘制两点之间的直线操作

    Unity 通过LineRenderer绘制两点之间的直线操作

    这篇文章主要介绍了Unity 通过LineRenderer绘制两点之间的直线操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2021-04-04
  • C# Task Cancellation使用总结

    C# Task Cancellation使用总结

    本文主要介绍了在使用CancellationTokenSource取消任务时的行为,以及如何使用Task的ContinueWith方法来处理任务的延续
    2024-12-12

最新评论