⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 default.aspx.cs

📁 在线脚本映射、ASP.net具体错误信息在线查看。先服务器上要确保安装rar软件
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Diagnostics;


namespace TreeRar
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //递归展示文件目录
            string[] dir = Directory.GetDirectories(Server.MapPath("\\"));
            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>");
            for (int i = 0; i < dir.Length; i++)
            {
                string href = dir[i];
                href = "http://"+Request.Url.Authority.ToString() + href.Substring(href.LastIndexOf("\\"));
                Response.Write("<tr     onmouseout=\"this.style.backgroundColor='#ffffff'\"   onmouseover=\"this.style.backgroundColor='#cccccc'\"><td>&nbsp;</td><td>" + dir[i] + "</td><td><a   href=" + href + ">打开</a></td></tr>");
            }
            Response.Write("</table>");
            lbTree.Text = Server.MapPath("\\");
            //   在此处放置用户代码以初始化页面   
        }

        //得到当前IP
        private string GetIP()
        {
            string[] IP_Ary;
            string strIP, strIP_list;
            strIP_list = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (strIP_list != null && strIP_list != "")
            {
                strIP_list = strIP_list.Replace("'", "");
                if (strIP_list.IndexOf(",") >= 0)
                {
                    IP_Ary = strIP_list.Split(',');
                    strIP = IP_Ary[0];
                }
                else
                {
                    strIP = strIP_list;
                }
            }
            else
            {
                strIP = "";
            }
            if (strIP == "")
            {
                strIP = Request.ServerVariables["REMOTE_ADDR"];
                strIP = strIP.Replace("'", "");
            }
            return strIP;
        }


        protected void btnZip_Click(object sender, EventArgs e)
        {
          //压缩
        String my51aspxRar;
        RegistryKey my51aspxReg;
        Object my51aspxObj;
        String my51aspxInfo;
        ProcessStartInfo my51aspxStartInfo;
        Process my51aspxProcess;
        try
        {
            my51aspxReg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\Shell\Open\Command");
            my51aspxObj = my51aspxReg.GetValue("");
            my51aspxRar = my51aspxObj.ToString();
            my51aspxReg.Close();
            my51aspxRar = my51aspxRar.Substring(1, my51aspxRar.Length - 7);
            my51aspxInfo = "a  -r  -ep1 51aspx.rar " + lbTree.Text + @"rar/51aspx.txt "+ lbTree.Text + @"rar";//这里为rar的压缩命令格式(也可以自行扩展)
            my51aspxStartInfo = new ProcessStartInfo();
            my51aspxStartInfo.FileName = my51aspxRar;
            my51aspxStartInfo.Arguments = my51aspxInfo;
            my51aspxStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            my51aspxStartInfo.WorkingDirectory = lbTree.Text + "rar"; ;//获取或设置要启动的进程的初始目录。
            my51aspxProcess = new Process();
            my51aspxProcess.StartInfo = my51aspxStartInfo;
            my51aspxProcess.Start();
            Response.Write("<font color=red>压缩成功</font>");
        }
        catch (Exception ex)
       {
            Response.Write(ex.ToString());
        }

        }

        protected void btnUnZip_Click(object sender, EventArgs e)
        {
         //解压缩
        String my51aspxRar;
        RegistryKey my51aspxReg;
        Object my51aspxObj;
        String my51aspxInfo;
        ProcessStartInfo my51aspxStartInfo;
        Process my51aspxProcess;
        try
        {
            my51aspxReg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRar.exe\Shell\Open\Command");
            my51aspxObj = my51aspxReg.GetValue("");
            my51aspxRar = my51aspxObj.ToString();
            my51aspxReg.Close();
            my51aspxRar = my51aspxRar.Substring(1, my51aspxRar.Length - 7);
            my51aspxInfo = " X " + lbTree.Text + @"rar/51aspx.rar " + " " + lbTree.Text + @"unRar";
            my51aspxStartInfo = new ProcessStartInfo();
            my51aspxStartInfo.FileName = my51aspxRar;
            my51aspxStartInfo.Arguments = my51aspxInfo;
            my51aspxStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            my51aspxProcess = new Process();
            my51aspxProcess.StartInfo = my51aspxStartInfo;
            my51aspxProcess.Start();
            Response.Write("<font color=red>解压缩成功</font>");
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }

        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -