locked
Treeview Directory.get files show only html files RRS feed

  • Question

  • User181930479 posted

    I am populating treeview from a folder structure , i want to show only the html file in the subdirectory , but when i click on the subdirectory , im getting the html file and other files and folders as well :

    suppose , "12-29-1987_AIO" is the directory that contains the html file , but it also contains subfolders and txt files , i only want to display in the treeview the html file nothing else , i have tried both search patterrns :  

    directory.GetFiles("index?.html",SearchOption.TopDirectoryOnly))

    directory.GetFiles("*.html",SearchOption.TopDirectoryOnly))

    but still getting all the files including the html file

    below is my code :

     public void getdirectoryname()
        {
    
            string[] subdirectoryEntries = Directory.GetDirectories(Server.MapPath("AIO-123"));
    
            foreach (string nameofsub in subdirectoryEntries)
            {
                string ora = new DirectoryInfo(nameofsub).Name;
    
                chooseYear.Items.Add(ora);
    
            }
        }
    
        private void PopulateTreeView(DirectoryInfo dirInfo, TreeNode treeNode)
        {
            foreach (DirectoryInfo directory in dirInfo.GetDirectories())
            {
    
                TreeNode directoryNode = new TreeNode
                {
                    Text = directory.Name,
                    Value = directory.FullName,
                    SelectAction = TreeNodeSelectAction.None
                };
    
                if (treeNode == null)
                {
                    //If Root Node, add to TreeView.
                     treeview1.Nodes.Add(directoryNode);
                }
                else
                {
                    //If Child Node, add to Parent Node.
                    treeNode.ChildNodes.Add(directoryNode);
                }
    
                //Get all files in the Directory.
    
    
                foreach (FileInfo file in directory.GetFiles("index?.html",SearchOption.TopDirectoryOnly))
                {
                    
                    //Add each file as Child Node.
                    TreeNode fileNode = new TreeNode
                    {
                        Text = file.Name,
                        Value = file.FullName,
                         
                        Target = "naf",
                       
                        NavigateUrl = ""
    
                       
                    };
                   
                    directoryNode.ChildNodes.Add(fileNode);
    
    
                    string fb = fileNode.Value;
    
    
                }
    
                PopulateTreeView(directory, directoryNode);
               
                   
            }
      
    }
    
    
        protected void chooseYear_SelectedIndexChanged(object sender, EventArgs e)
        {
            treeview1.Nodes.Clear();
            DirectoryInfo rootInfo = new DirectoryInfo(Server.MapPath("AIO-123\\" + chooseYear.SelectedValue.ToString()));
            this.PopulateTreeView(rootInfo, null);
            treeview1.CollapseAll();
    
        }
    
       
        protected void treeview1_SelectedNodeChanged(object sender, EventArgs e)
        {
    
            
    
    
             complete = treeview1.SelectedNode.Value;
            
            
    
                 string ora = treeview1.SelectedNode.Value.Substring(14);
    
                 string naf111 = ora.Replace("\\", "/");
                 MyIframe.Attributes.Add("src", naf111);
     
             }

    I NEED HELP ON THIS.....

    Thursday, April 5, 2018 6:41 AM

All replies