zoukankan      html  css  js  c++  java
  • Asp.net调用RAR压缩 解压文件

    //压缩
        protected void btnY_Click(object sender, EventArgs e)
        
    {
            
    string rar;
            RegistryKey reg;
            
    string args;
            ProcessStartInfo procStart;
            Process process;
            
    try
            
    {
                reg 
    = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\Shell\Open\Command");
                rar 
    = reg.GetValue("").ToString();//获取注册表rar安装路径
                reg.Close();
                rar 
    = rar.Substring(1, rar.Length - 7);//获取rar安装路径
                args = "a -inul -y G:\\temp.rar G:\\1.txt";//这里为rar的压缩命令格式(也可以自行扩展)
                procStart = new ProcessStartInfo();
                procStart.FileName 
    = rar;
                procStart.Arguments 
    = args;//参数
                procStart.WindowStyle = ProcessWindowStyle.Hidden;//窗口状态
                procStart.WorkingDirectory = Server.MapPath(""); ;//获取或设置要启动的进程的初始目录。
                process = new Process();
                process.StartInfo 
    = procStart;
                process.Start();
                Response.Write(
    "<script>alert('压缩成功')</script>");
            }

            
    catch (Exception ex)
            
    {
                Response.Write(ex.ToString());
            }

        }

        
    //解压
        protected void btnJ_Click(object sender, EventArgs e)
        
    {
            
    string rar;
            RegistryKey reg;
            
    string args;
            ProcessStartInfo startInfo;
            Process process;
            
    try
            
    {
                reg 
    = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRar.exe\Shell\Open\Command");
                rar 
    = reg.GetValue("").ToString();
                reg.Close();
                rar 
    = rar.Substring(1, rar.Length - 7);
                args 
    = " X E:\\temp.rar E:\\";
                startInfo 
    = new ProcessStartInfo();
                startInfo.FileName 
    = rar;
                startInfo.Arguments 
    = args;
                startInfo.WindowStyle 
    = ProcessWindowStyle.Hidden;
                process 
    = new Process();
                process.StartInfo 
    = startInfo;
                process.Start();
                Response.Write(
    "<script>alert('解压成功')</script>");
            }

            
    catch (Exception ex)
            
    {
                Response.Write(ex.ToString());
            }

        }
  • 相关阅读:
    JAVA中变量的类型及命名规范
    JAVA、JDK等入门概念,下载安装JAVA并配置环境变量
    大家好,我是一个JAVA初学者,想在这里记下自己学习过程中的点点滴滴,请多多关照
    多线程并发问题解决之redis锁
    设计模式之动态代理
    设计模式之静态代理
    spring之IOC模拟实现
    spring boot+kafka整合
    metrics+spring+influxdb整合
    MongoError: no primary found in replicaset
  • 原文地址:https://www.cnblogs.com/taizhouxiaoba/p/1729687.html
Copyright © 2011-2022 走看看