zoukankan      html  css  js  c++  java
  • asp.net 在线解压缩文件类

    1. using System;  
    2. using System.Collections.Generic;  
    3. using System.Text;  
    4. using System.IO;  
    5. using Microsoft.Win32;  
    6. using System.Diagnostics;  
    7. using System.Web;  
    8.     public class Winrar  
    9.     {  
    10.         /// <summary>  
    11.         /// 是否安装了Winrar  
    12.         /// </summary>  
    13.         /// <returns></returns>  
    14.         static public bool Exists()  
    15.         {  
    16.             RegistryKey the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE/Microsoft/Windows/CurrentVersion/App Paths/WinRAR.exe");  
    17.             return !string.IsNullOrEmpty(the_Reg.GetValue("").ToString());  
    18.         }  
    19.         /// <summary>  
    20.         /// 打包成Rar  
    21.         /// </summary>  
    22.         /// <param name="patch"></param>  
    23.         /// <param name="rarPatch"></param>  
    24.         /// <param name="rarName"></param>  
    25.         public string CompressRAR(string patch, string rarPatch, string rarName)  
    26.         {  
    27.             string the_rar;  
    28.             RegistryKey the_Reg;  
    29.             object the_Obj;  
    30.             string the_Info;  
    31.             ProcessStartInfo the_StartInfo;  
    32.             Process the_Process;  
    33.             try  
    34.             {  
    35.                 the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE/Microsoft/Windows/CurrentVersion/App Paths/WinRAR.exe");  
    36.                 the_Obj = the_Reg.GetValue("");  
    37.                 the_rar = the_Obj.ToString();  
    38.                 the_Reg.Close();  
    39.                 the_rar = the_rar.Substring(1, the_rar.Length - 7);  
    40.                 Directory.CreateDirectory(patch);  
    41.                 //命令参数  
    42.                 //the_Info = " a    " + rarName + "  " + @"C:Test?70821.txt"; //文件压缩  
    43.                 the_Info = " a    " + rarName + "  " + patch + "  -r"; ;  
    44.                 the_StartInfo = new ProcessStartInfo();  
    45.                 the_StartInfo.FileName = the_rar;  
    46.                 the_StartInfo.Arguments = the_Info;  
    47.                 the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;  
    48.                 //打包文件存放目录  
    49.                 the_StartInfo.WorkingDirectory = rarPatch;  
    50.                 the_Process = new Process();  
    51.                 the_Process.StartInfo = the_StartInfo;  
    52.                 the_Process.Start();  
    53.                 the_Process.WaitForExit();  
    54.                 the_Process.Close();  
    55.             }  
    56.             catch (Exception ex)  
    57.             {  
    58.                 return ex.Message;  
    59.             }  
    60.             return string.Empty;  
    61.         }  
    62.         /// <summary>  
    63.         /// 解压  
    64.         /// </summary>  
    65.         /// <param name="unRarPatch"></param>  
    66.         /// <param name="rarPatch"></param>  
    67.         /// <param name="rarName"></param>  
    68.         /// <returns></returns>  
    69.         public string unCompressRAR(string unRarPatch, string rarPatch, string rarName)  
    70.         {  
    71.             string the_rar;  
    72.             RegistryKey the_Reg;  
    73.             object the_Obj;  
    74.             string the_Info;  
    75.             try  
    76.             {  
    77.                 the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE/Microsoft/Windows/CurrentVersion/App Paths/WinRAR.exe");  
    78.                 the_Obj = the_Reg.GetValue("");  
    79.                 the_rar = the_Obj.ToString();  
    80.                 the_Reg.Close();  
    81.                 //the_rar = the_rar.Substring(1, the_rar.Length - 7);  
    82.                 if (Directory.Exists(unRarPatch) == false)  
    83.                 {  
    84.                     Directory.CreateDirectory(unRarPatch);  
    85.                 }  
    86.                 the_Info = "x /"" + rarName + "/" /"" + unRarPatch + "/" -y";  
    87.                 ProcessStartInfo the_StartInfo = new ProcessStartInfo();  
    88.                 the_StartInfo.FileName = the_rar;  
    89.                 the_StartInfo.Arguments = the_Info;  
    90.                 the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;  
    91.                 the_StartInfo.WorkingDirectory = rarPatch;//获取压缩包路径  
    92.                 Process the_Process = new Process();  
    93.                 the_Process.StartInfo = the_StartInfo;  
    94.                 the_Process.Start();  
    95.                 the_Process.WaitForExit();  
    96.                 the_Process.Close();  
    97.             }  
    98.             catch (Exception ex)  
    99.             {  
    100.                 return ex.Message;  
    101.             }  
    102.             return string.Empty;  
    103.         }  
    104.     }  
  • 相关阅读:
    HDU 3416 Marriage Match IV(SPFA+最大流)
    asp.net一些很酷很实用的.Net技巧
    asp.net部分控件使用和开发技巧总结
    ASP_NET Global_asax详解
    asp.net 多字段模糊查询代码
    Asp.net中防止用户多次登录的方法
    SQL Server 事务、异常和游标
    有关Cookie
    asp.net 连接sql server 2005 用户 'sa' 登录失败。asp.net开发第一步连接的细节问题
    asp.net生成高质量缩略图通用函数(c#代码),支持多种生成方式
  • 原文地址:https://www.cnblogs.com/lyl6796910/p/4070710.html
Copyright © 2011-2022 走看看