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

  • 相关阅读:
    我是如何学习和工作的(1)
    SQL server事物复制报错:要复制的 LOB 数据的长度(xxxxx)超出了配置的最大值 65536
    SQL Server2012高可用之事物复制(发布订阅)测试
    MySQL参数学习(一)
    Oracle间隔(interval)分区
    oracle异机恢复测试
    使用awrsqrpt.sql查看执行计划demo
    使用10046追踪执行计划demo
    js中call、apply和bind到底有什么区别?
    为什么0.1+0.2=0.30000000000000004
  • 原文地址:https://www.cnblogs.com/zhoukuan0905/p/2113079.html
Copyright © 2011-2022 走看看