zoukankan      html  css  js  c++  java
  • 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. }
    联盟快卖 商人,生意人,待创业人士在此可以共赢互利 期待你的加入 群号:140809277
  • 相关阅读:
    架构师养成记--19.netty
    架构师养成记--18.NIO
    架构师养成记--17.disrunptor 多生产者多消费者
    JS计算字符长度、字节数 -- 转
    BootStrap Modal 点击空白时自动关闭
    架构师养成记--16.disruptor并发框架中RingBuffer的使用
    架构师养成记--15.Disruptor并发框架
    架构师养成记--14.重入锁ReentrantLock 和 读写锁 ReentrantReadWriteLock
    049、Java中使用switch判断,不加入break时的操作
    048、Java中使用switch判断
  • 原文地址:https://www.cnblogs.com/yexinw/p/2280211.html
Copyright © 2011-2022 走看看