Click here to Skip to main content
Click here to Skip to main content

Directory Browsing in ASP.Net 2.0

, 16 Apr 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
An article on browsing via directories or HTTP, with ASP.NET using Tree View Control
Download - 18.72 KB
Screenshot - main.JPG


The file uploder is the control which help to select the file but not the path of the file or directory and also we can't make a Active X Control for this so with the help of pop-up we provide the user to select file or directory path in the intranet. This pop-up look same like the directory browing in desktop application. 


I read this article which is in 1.1. I have changed the folder structure with tree view.

Using the code

Create a C# web application in 2.0 and add BrowseDirectory.aspx and add following files into your app_code folder

  • WebForm1_aspx_cs_FileList.cs
  • WebForm1_aspx_cs_PathHelper.cs

and create a textbox and button on which webform you want to use it. Add onClientClick of the button and set OnClientClick="showDirectory();" . Add this script into yout web form for calling the browsing page.

function showDirectory()
                document.all.TextBox1.value= window.showModalDialog("browseDirectory.aspx",
                            "dialogHeight: 560px; dialogWidth:360px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: No;"); 
                return false;



Explanation of code blocks

Add Node method in the BrowseDirectory.aspx which add the tree node of the directory and files. FileList Constructor takes path and the filters for the files

            FileList objList = new FileList(path, "*.*");
            TreeNode node = new TreeNode(path,path);
            for(int index = 0 ; index < objList.Directories.Length ; index++)
                string directory = objList.Directories[index];            
                TreeNode objChildNode = new TreeNode(directory, path + "\\" + directory + "\\"); 
                objChildNode.PopulateOnDemand = true;
                objChildNode.Target = "_blank";
            foreach (string file in objList.Files)
                TreeNode objChildNode = new TreeNode(file, path + "\\" + file);
            return node;

For selecting the path of the file or directory use the selection event of the tree view

            void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
                _browseTextBox.Text = TreeView1.SelectedValue;

Expanding is base on the directory selection.

             void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
                if (e.Node.Value.EndsWith("\\"))
                    AddNodes(e.Node.Value, e.Node); 


Finally when you select the path then go back to the parent page with this path

            <script language="javascript">
                function SelectAndClose()
		                txtValue = document.getElementById('_browseTextBox');
		                window.returnValue = txtValue.value;
		                return false;


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


About the Author

Rupesh Burad
Team Leader Nagarro Software Pvt Ltd.
India India
No Biography provided

Comments and Discussions

GeneralMy vote of 3 PinmemberMember 41393824-Apr-14 10:26 
Suggestionyour code does not display all folder in particular drive in vs2010 [modified] Pinmembersankmahesh24-Oct-13 0:58 
Questionwill this treeview fetches the data from server folders or local system folders? Pinmemberaravind0627-Sep-13 21:05 
AnswerRe: will this treeview fetches the data from server folders or local system folders? Pinmemberankurmee31-Jan-14 2:59 
QuestionCan u give this project in vb codings ? PinprofessionalAravindba21-Jul-13 7:21 
Bugbug on expanding node PinmemberIosif_petre188-Apr-13 11:31 
QuestionBrowsing Namespace PinmemberFranco Cipriano23-Jul-12 5:45 
QuestionDirectory Browsing Pinmemberanandkumar018822-May-12 1:55 
QuestionVB source Pinmemberhighglow23-Apr-12 7:26 
QuestionNot able to browse network drive Pinmemberajitsingh41711-Jan-12 3:09 
QuestionUn Know in Fire Fox PinmemberPhan Van Thao25-Sep-11 18:06 
GeneralQuestion [modified] PinmemberAtul Naik21-Sep-11 3:03 
GeneralDirectory browser Pinmembersrinivas prabhu20-Aug-10 2:37 
GeneralRe: Directory browser PinmemberRupesh Burad22-Aug-10 19:48 
GeneralRe: Directory browser Pinmemberselllllllllllllll8-Sep-11 2:50 
GeneralMy vote of 1 Pinmemberzdlik5-Feb-10 13:36 
QuestionThanks....? PinmemberMember 412614913-Nov-09 22:37 
GeneralDirectory Browsing in ASP.Net 2.0 Pinmemberab_sdfdsfsdf20-Oct-09 8:31 
GeneralHi! Pinmemberweiiis11-Aug-09 4:42 
GeneralThanks PinmemberIntellect22-Mar-09 20:32 
GeneralMy vote of 1 Pinmemberjoshuaemory31-Dec-08 6:21 
QuestionSource code Pinmemberclbmribas12-Jul-08 10:59 
QuestionNeed Source PinmemberJeff Bowman27-Dec-07 19:10 
GeneralRe: Need Source PinmemberRupesh Burad16-Apr-08 0:27 
GeneralRe: Need Source PinmemberJeff Bowman19-Apr-08 16:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 16 Apr 2008
Article Copyright 2007 by Rupesh Burad
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid