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;
            }

  • 相关阅读:
    LeetCode 1109 航班预定统计
    leetcode 138 复制带随机指针的链表
    maven导入org.apache.pdfbox
    Intellij Idea 通过svn或者git提交代码时速度慢的解决办法
    java LocalDateTime 加减当前时间
    git命令--拉取代码和切换分支
    Intellij IDEA插件Free Mybatis plugin
    MySQL 生成随机字符串 uuid
    最新版Navicat Premium v15.0.26 中文破解
    算法——二分法查找
  • 原文地址:https://www.cnblogs.com/zhoukuan0905/p/2113079.html
Copyright © 2011-2022 走看看