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());
            }
  • 相关阅读:
    A1052. Linked List Sorting (25)
    A1032. Sharing (25)
    A1022. Digital Library (30)
    A1071. Speech Patterns (25)
    A1054. The Dominant Color (20)
    A1060. Are They Equal (25)
    A1063. Set Similarity (25)
    电子码表
    矩阵键盘
    对象追踪、临时对象追踪、绝对坐标与相对坐标
  • 原文地址:https://www.cnblogs.com/zwffff/p/1441535.html
Copyright © 2011-2022 走看看