Click here to Skip to main content
13,594,802 members
Click here to Skip to main content
Add your own
alternative version


33 bookmarked
Posted 13 Sep 2004
Licenced CPOL

Folder, Drive, Directory Browser

, 13 Sep 2004
Rate this:
Please Sign up or sign in to vote.
Folder, drive, directory browser application.


This source code is written and maintained by an individual, not a company. It has been provided for free to the Microsoft .NET user community with the expectation that users will take whatever action necessary to get the code to operate according to their needs. This includes debugging and enhancements. The source code is provided "as is" and there are neither warrantees to the quality of the work nor any expressed or implied agreements that the programmer will release any updates. The programmer will release updates and provide any support at his own discretion.


The article is mainly for beginners of .NET WinForms programming. Recently, I heard that quite a few people have questions on developing the folder and file dialog boxes. Actually, it is a simple and easy one. This article is to give a simple example in VB.NET as well as in C# showing that how easy it is to create a custom drive list Box, directory list box and a file list box. This is developed using Visual Studio .NET final release.

Adding "DriveListBox", "DirListBox", and "FileListBox" to VS.NET Toolbox:

Select ‘Tools’ menu and Select ‘Add/Remove Tool Box Items’. Then the ‘Customize Toolbox’ will appear in the screen. Select ‘.NET Framework Components’ tab and then select the ‘DriveListBox’, ‘DirListBox’, and ‘FileListBox’ checkboxes and hit OK. Now you can drag and drop the "DriveListBox", "DirListBox", and "FileListBox" into a Windows Form.

driveListBox_SelectedIndex Method:

When the user selects a drive from the DriveListBox drop-down list, this method updates the path of the DirListBox to be consistent with the DriveListBox. If the drive is unavailable or missing or if there is some other problem, then it will show a message on the screen with the error alert and the DriveListBox. The drive is then restored to its original selection.

private void driveListBox1_SelectedIndexChanged(object sender, System.EventArgs e)
        this.dirListBox1.Path = this.driveListBox1.Drive;
    catch(Exception ex)
        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, 


When the user double-clicks on a folder, or the DirListBox is updated because the drive was changed, this method updates the Path of the FileListBox to be consistent with the DirListBox. If the directory is unavailable or missing or if there is some other problem then it will show a message on the screen with the error alert.

private void dirListBox1_SelectedIndexChanged(object sender, System.EventArgs e)
        this.fileListBox1.Path = this.dirListBox1.Path;
        this.lblFolder.Text = 
    catch(Exception ex)
        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, 

To exit from the application, use the following code:

private void Exit_Click(object sender, System.EventArgs e)

For more help and queries, please mail me:


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


About the Author

Chief Technology Officer at Zealots
Australia Australia
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralThanks Pin
JohnAnas24-Feb-11 2:06
memberJohnAnas24-Feb-11 2:06 
GeneralMy vote of 4 Pin
aashish7729-Sep-10 6:00
memberaashish7729-Sep-10 6:00 
GeneraldirListBox1_Changed Pin
HunB23-May-08 0:19
memberHunB23-May-08 0:19 
GeneralThis is very usefull for me Pin
xkermit21-Apr-07 1:58
memberxkermit21-Apr-07 1:58 
GeneralTHX Pin
Highmaster21-Feb-05 13:24
memberHighmaster21-Feb-05 13:24 
GeneralRe: THX Pin
vivekthangaswamy24-Feb-05 2:33
membervivekthangaswamy24-Feb-05 2:33 

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

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

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.180621.3 | Last Updated 14 Sep 2004
Article Copyright 2004 by vivekthangaswamy
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid