Click here to Skip to main content
12,955,007 members (64,115 online)
Click here to Skip to main content
Add your own
alternative version


22 bookmarked
Posted 2 Dec 2002

A very simple BrowseForFolder class

, 2 Dec 2002
Rate this:
Please Sign up or sign in to vote.
A very simple class to include the browse for folder window into your C# project

Sample Image - browseforfolder.png


There is a lot of code on the net about the browse for folder window, but when I was starting to learn C# I didn't find any really good example and description of how to use it. Someone still used the old API to call it, someone else didn't say anything about the System.Design.dll and, however, I didn't find any demo project, always only few lines of code. For a beginner this is not a true help... so, I'm posting here a simple class, a demo project and all the instructions to add the useful BrowseForFolder window into your .NET programs.

Using the code

Ok, let's start.

first of all you have to include into your project the BrowseForFolder class (File/Add Existing Item from menu and select the BrowseForFolder.cs file), then you have to include the System.Design.dll in your References (Project/Add Reference from menu).

Now you can add this line of code in the namespace declaration:
using Utility.BrowseForFolder;

[Sure, this is an optional step (you can change the BrowseForFolder class's namespace to your program namespace), but I suggest you to keep it as a general code, in other words to build a collection of useful and indipendent little bricks of code.]

The last step is to add these few lines of code in your program:

string myPath;

BrowseForFolderClass myFolderBrowser = new BrowseForFolderClass();
myPath = myFolderBrowser.BrowseForFolder("enter_here_your_text");

Ok, you have done it! ;-) Now into myPath you have the user selected path, otherwise if the user has pressed the Cancel button into myPath you'll have a blank field (myPath -> "").

Note: The path returned form myFolderBrowser.BrowseForFolder will always end with a "\" character.

Points of Interest

There are a lot of comments with the code, so... enjoy!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Francesco Natali
Web Developer
Italy Italy
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralA 100% .NET solution: Pin
Frans Bouma10-Dec-02 23:30
memberFrans Bouma10-Dec-02 23:30 
GeneralShell API solution Pin
Barrett8085-Dec-02 7:37
memberBarrett8085-Dec-02 7:37 
GeneralRe: Shell API solution Pin
Anonymous7-Feb-05 4:50
sussAnonymous7-Feb-05 4:50 
QuestionRisky? Pin
Michael Potter4-Dec-02 4:03
memberMichael Potter4-Dec-02 4:03 
AnswerRe: Risky? Pin
David Stone4-Dec-02 13:54
memberDavid Stone4-Dec-02 13:54 

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 | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 3 Dec 2002
Article Copyright 2002 by Francesco Natali
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid