zoukankan      html  css  js  c++  java
  • 【摘录】Asp.net实现在线压缩与解压

    首先加入命名空间

    using Microsoft.Win32;
    using System.Runtime.InteropServices;
    using System.Diagnostics;

    实现压缩方法:


    //压缩
            String strRar;
            RegistryKey rkReg;
            Object obj;
            String strInfo;
            ProcessStartInfo psiInfo;
            Process pProcess;
            
    try
            {
                rkReg 
    = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\Shell\Open\Command");
                obj 
    = rkReg.GetValue("");
                strRar 
    = obj.ToString();
                rkReg.Close();
                strRar 
    = strRar.Substring(1, strRar.Length - 7);
                strInfo 
    = "a  -r  -ep1 test.rar " + lblTree.Text + @"rar/test1.txt " + lblTree.Text + @"rar";//这里为rar的压缩命令格式(也可以自行扩展)
                psiInfo = new ProcessStartInfo();
                psiInfo.FileName 
    = strRar;
                psiInfo.Arguments 
    = strInfo;
                psiInfo.WindowStyle 
    = ProcessWindowStyle.Hidden;
                psiInfo.WorkingDirectory 
    = lblTree.Text + "rar"; ;//获取或设置要启动的进程的初始目录。
                pProcess = new Process();
                pProcess.StartInfo 
    = psiInfo;
                pProcess.Start();
                Response.Write(
    "<font color=red>压缩成功</font>");
            }
            
    catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }

    实现解压方法:

    //解压缩
            String strRar;
            RegistryKey rkReg;
            Object obj;
            String strInfo;
            ProcessStartInfo psiInfo;
            Process pProcess;
            
    try
            {
                rkReg 
    = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRar.exe\Shell\Open\Command");
                obj 
    = rkReg.GetValue("");
                strRar 
    = obj.ToString();
                rkReg.Close();
                strRar 
    = strRar.Substring(1, strRar.Length - 7);
                strInfo 
    = " X " + lblTree.Text + @"rar/test.rar " + " " + lblTree.Text + @"unRar";
                psiInfo 
    = new ProcessStartInfo();
                psiInfo.FileName 
    = strRar;
                psiInfo.Arguments 
    = strInfo;
                psiInfo.WindowStyle 
    = ProcessWindowStyle.Hidden;
                pProcess 
    = new Process();
                pProcess.StartInfo 
    = psiInfo;
                pProcess.Start();
                Response.Write(
    "<font color=red>解压缩成功</font>");
            }
            
    catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
  • 相关阅读:
    mysql 事务只读: Could not retrieve transation read-only status server
    页面加载空白---(failed)net::ERR_INCOMPLETE_CHUNKED_ENCODING
    关于数据库mysql死锁:MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
    高性能分布式锁-redisson的使用
    C/S程序抓包
    linux 安装maven
    linux之jdk安装及环境
    腾讯云服务器搭建之mysql
    mysql去重保留id最小的
    MySQL中文全文检索
  • 原文地址:https://www.cnblogs.com/zwffff/p/1441535.html
Copyright © 2011-2022 走看看