C#调用winrar进行压缩和解压缩

using Microsoft.Win32;
using System.Diagnostics;
压缩

  1. string the_rar;
  2. RegistryKey the_Reg;
  3. object the_Obj;
  4. string the_Info;
  5. ProcessStartInfo the_StartInfo;
  6. Process the_Process;
  7. try
  8. {
  9. the_Reg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\Shell\Open\Command");
  10. the_Obj = the_Reg.GetValue("");
  11. the_rar = the_Obj.ToString();
  12. the_Reg.Close();
  13. the_rar = the_rar.Substring(1, the_rar.Length - 7);
  14. the_Info = " a " + " test.rar " + " " + @"C:\test\test.txt";
  15. the_StartInfo = new ProcessStartInfo();
  16. the_StartInfo.FileName = the_rar;
  17. the_StartInfo.Arguments = the_Info;
  18. the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  19. the_StartInfo.WorkingDirectory = @"C:\test\";
  20. the_Process = new Process();
  21. the_Process.StartInfo = the_StartInfo;
  22. the_Process.Start();
  23. Response.Write("<script>alert('Zip Successfully');</script>");
  24. }
  25. catch
  26. {
  27. Response.Write("<script>alert('Zip Failed.')</script>");
  28. }

解压缩

  1. string the_rar;
  2. RegistryKey the_Reg;
  3. object the_Obj;
  4. string the_Info;
  5. ProcessStartInfo the_StartInfo;
  6. Process the_Process;
  7. try
  8. {
  9. the_Reg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\Shell\Open\Command");
  10. the_Obj = the_Reg.GetValue("");
  11. the_rar = the_Obj.ToString();
  12. the_Reg.Close();
  13. the_rar = the_rar.Substring(1, the_rar.Length - 7);
  14. the_Info = " X " + " test.rar " + @"C:\test\";
  15. the_StartInfo = new ProcessStartInfo();
  16. the_StartInfo.FileName = the_rar;
  17. the_StartInfo.Arguments = the_Info;
  18. the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  19. the_StartInfo.WorkingDirectory = @"C:\test\";
  20. the_Process = new Process();
  21. the_Process.StartInfo = the_StartInfo;
  22. the_Process.Start();
  23. Response.Write("<script>alert('UnZip Successfully');</script>");
  24. }
  25. catch
  26. {
  27. Response.Write("<script>alert('UnZip Failed.')</script>");
  28. }
posted @   易独  阅读(249)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
乐巴儿 一个有声音的公众号
长按,识别二维码,加关注
点击右上角即可分享
微信分享提示