压缩、解压

 
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.IO;
  12. using Microsoft.Win32;
  13. using System.Runtime.InteropServices;
  14. using System.Diagnostics;
  15. //该源码下载自www.51aspx.com(51aspx.com)
  16. namespace TreeRar
  17. {
  18.     public partial class _Default : System.Web.UI.Page
  19.     {
  20.         protected void Page_Load(object sender, EventArgs e)
  21.         {
  22.             //递归展示文件目录
  23.             string[] dir = Directory.GetDirectories(Server.MapPath("//"));
  24.             Response.Write("<table   width=100%   border=1   rules=rows   cellspacing=0   colspacing=0><tr   height=60   bgColor=#339900><td colspan=3 style=/"color=#FFFFFF/">目录列表:</td></tr>");
  25.             for (int i = 0; i < dir.Length; i++)
  26.             {
  27.                 string href = dir[i];
  28.                 href = "http://"+Request.Url.Authority.ToString() + href.Substring(href.LastIndexOf("//"));
  29.                 Response.Write("<tr     onmouseout=/"this.style.backgroundColor='#ffffff'/"   onmouseover=/"this.style.backgroundColor='#cccccc'/"><td> </td><td>" + dir[i] + "</td><td><a   href=" + href + ">打开</a></td></tr>");
  30.             }
  31.             Response.Write("</table>");
  32.             lbTree.Text = Server.MapPath("//");
  33.             //   在此处放置用户代码以初始化页面   
  34.         }
  35.         //得到当前IP
  36.         private string GetIP()
  37.         {
  38.             string[] IP_Ary;
  39.             string strIP, strIP_list;
  40.             strIP_list = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
  41.             if (strIP_list != null && strIP_list != "")
  42.             {
  43.                 strIP_list = strIP_list.Replace("'""");
  44.                 if (strIP_list.IndexOf(",") >= 0)
  45.                 {
  46.                     IP_Ary = strIP_list.Split(',');
  47.                     strIP = IP_Ary[0];
  48.                 }
  49.                 else
  50.                 {
  51.                     strIP = strIP_list;
  52.                 }
  53.             }
  54.             else
  55.             {
  56.                 strIP = "";
  57.             }
  58.             if (strIP == "")
  59.             {
  60.                 strIP = Request.ServerVariables["REMOTE_ADDR"];
  61.                 strIP = strIP.Replace("'""");
  62.             }
  63.             return strIP;
  64.         }
  65.         protected void btnZip_Click(object sender, EventArgs e)
  66.         {
  67.           //压缩
  68.         String my51aspxRar;
  69.         RegistryKey my51aspxReg;
  70.         Object my51aspxObj;
  71.         String my51aspxInfo;
  72.         ProcessStartInfo my51aspxStartInfo;
  73.         Process my51aspxProcess;
  74.         try
  75.         {
  76.             my51aspxReg = Registry.ClassesRoot.OpenSubKey(@"Applications/WinRAR.exe/Shell/Open/Command");
  77.             my51aspxObj = my51aspxReg.GetValue("");
  78.             my51aspxRar = my51aspxObj.ToString();
  79.             my51aspxReg.Close();
  80.             my51aspxRar = my51aspxRar.Substring(1, my51aspxRar.Length - 7);
  81.             my51aspxInfo = "a  -r  -ep1 51aspx.rar " + lbTree.Text + @"rar/51aspx.txt "+ lbTree.Text + @"rar";//这里为rar的压缩命令格式(也可以自行扩展)
  82.             my51aspxStartInfo = new ProcessStartInfo();
  83.             my51aspxStartInfo.FileName = my51aspxRar;
  84.             my51aspxStartInfo.Arguments = my51aspxInfo;
  85.             my51aspxStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  86.             my51aspxStartInfo.WorkingDirectory = lbTree.Text + "rar"; ;//获取或设置要启动的进程的初始目录。
  87.             my51aspxProcess = new Process();
  88.             my51aspxProcess.StartInfo = my51aspxStartInfo;
  89.             my51aspxProcess.Start();
  90.             Response.Write("<font color=red>压缩成功</font>");
  91.         }
  92.         catch (Exception ex)
  93.        {
  94.             Response.Write(ex.ToString());
  95.         }
  96.         }
  97.         protected void btnUnZip_Click(object sender, EventArgs e)
  98.         {
  99.          //解压缩
  100.         String my51aspxRar;
  101.         RegistryKey my51aspxReg;
  102.         Object my51aspxObj;
  103.         String my51aspxInfo;
  104.         ProcessStartInfo my51aspxStartInfo;
  105.         Process my51aspxProcess;
  106.         try
  107.         {
  108.             my51aspxReg = Registry.ClassesRoot.OpenSubKey(@"Applications/WinRar.exe/Shell/Open/Command");
  109.             my51aspxObj = my51aspxReg.GetValue("");
  110.             my51aspxRar = my51aspxObj.ToString();
  111.             my51aspxReg.Close();
  112.             my51aspxRar = my51aspxRar.Substring(1, my51aspxRar.Length - 7);
  113.             my51aspxInfo = " X " + lbTree.Text + @"rar/51aspx.rar " + " " + lbTree.Text + @"unRar";
  114.             my51aspxStartInfo = new ProcessStartInfo();
  115.             my51aspxStartInfo.FileName = my51aspxRar;
  116.             my51aspxStartInfo.Arguments = my51aspxInfo;
  117.             my51aspxStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  118.             my51aspxProcess = new Process();
  119.             my51aspxProcess.StartInfo = my51aspxStartInfo;
  120.             my51aspxProcess.Start();
  121.             Response.Write("<font color=red>解压缩成功</font>");
  122.         }
  123.         catch (Exception ex)
  124.         {
  125.             Response.Write(ex.ToString());
  126.         }
  127.         }
  128.     }
  129. }
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值