Click here to Skip to main content
15,889,754 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Everyone, How can I browse folders rather than browsing files in Asp.net 4.5. FYI, my requirement is something like I should be able to pick a folder and count no. of files in folder and subfolders. But unfortunately I couldn't find the mechanism to browse for folders.

Thanks in advance.
Posted
Comments
Thanks7872 10-Apr-15 6:21am    
Where is the question? What have you tried so far. And what do you mean by 'I couldn't find the mechanism to browse for folders'?

 
Share this answer
 
Thank you for your concern,

At first, I've tried at first to select folder by using FileUpload control, but we can only choose files but not any folder through that.

And I've used TreeView control to populate the directories starting from the "My Computer" as default start-up path of the current user. But I couldn't get the my computer (this pc) path of Windows 8.

C#
protected void Page_Load(object sender, EventArgs e)
    {
        //set the treeview's first node to our Images folder

        string path = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);

        TreeView1.Nodes[0].Value = path;
    }

    protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
    {
        if (IsCallback)
        {
            if (e.Node.ChildNodes.Count == 0)
            {
                DirectoryInfo directory = null;
                directory = new DirectoryInfo(e.Node.Value);

                foreach (DirectoryInfo subtree in directory.GetDirectories())
                {
                    TreeNode subNode = new TreeNode(subtree.Name);
                    subNode.Value = subtree.FullName;
                    try
                    {
                        if (subtree.GetDirectories().Length > 0 | subtree.GetFiles().Length > 0)
                        {
                            subNode.SelectAction = TreeNodeSelectAction.SelectExpand;
                            subNode.PopulateOnDemand = true;
                            subNode.NavigateUrl = "#";
                        }
                    }
                    catch
                    {

                    }
                    e.Node.ChildNodes.Add(subNode);
                }
                foreach (FileInfo fi in directory.GetFiles())
                {
                    TreeNode subNode = new TreeNode(fi.Name);
                    e.Node.ChildNodes.Add(subNode);
                    subNode.NavigateUrl = "Images/" + fi.Name.ToString();
                }
            }
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900