zoukankan      html  css  js  c++  java
  • ASP.NET中用TreeView 浏览网站目录内容

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {

          TreeNode node2 = new TreeNode();
                    node2.Text = "根目录";
                    node2.Value = Server.MapPath("../");
                    TreeView2.Nodes.Add(node2);
                    getsubfile(TreeView2.Nodes[0]);
                }
            }

            /// <summary>   
           /// 显示所选节点下所有的文件和文件夹,用递归显示,一次性完整显示,如果文件过多性能很差,   
           /// 可以每次只显示2层,然后选择显示   
           ///  </summary>   
           /// <param name="tn">选择的节点</param>   
           /// <returns></returns>   
            public bool getsubfile(TreeNode tn)
            {
                DirectoryInfo di = new DirectoryInfo(tn.Value);
                int allNum = di.GetDirectories().Length + di.GetFiles("*.*").Length;
                if (allNum == 0) //如果其下的文件和文件夹为空则返回       
                {
                    return false;
                }
                //循环显示文件夹 每个节点只设置Name和Value,value存完整路径。       
                foreach (DirectoryInfo subdir in di.GetDirectories())
                {
                   
                        TreeNode subtd = new TreeNode();
                        subtd.Text = subdir.Name;
                        subtd.Value = subdir.FullName;
                        tn.ChildNodes.Add(subtd);
                        getsubfile(subtd);
                   
                }
                //循环显示文件       
                foreach (FileInfo subfile in di.GetFiles())
                {
                    if (subfile.Extension == ".aspx" || subfile.Extension == ".html" || subfile.Extension == ".gif" || subfile.Extension == ".jpg")
                    {
                        TreeNode subtd = new TreeNode();
                        subtd.Text = subfile.Name;
                        subtd.Value = subfile.FullName;
                        tn.ChildNodes.Add(subtd);
                    }
                }
                return true;
            }

  • 相关阅读:
    MySQL之三---MySQL数据库的二进制安装、源码编译和基础入门操作
    yum仓库搭建、http源码编译和磁盘分区
    linux 磁盘管理三部曲——(3)mount挂载,/etc/fstab配置文件
    linux 磁盘管理三部曲——(2)管理分区,文件系统类型格式化
    linux 磁盘管理三部曲——(1)磁盘结构,认识分区
    ssh WARNING:REMOTE HOST IDENTIFICATION HAS CHANGED(警告:远程主机标识已更改)
    httpd源码编译安装
    001 直接throw new RuntimeException("xxx")的异常错误信息是谁打印的?
    77 注解(二)——反射机制读取注解
    76 注解(一)——常用注解、自定义注解、注解的参数
  • 原文地址:https://www.cnblogs.com/zhoukuan0905/p/2113079.html
Copyright © 2011-2022 走看看