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

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

Introduction

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! Wink | ;-) 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!

License

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

Share

About the Author

Francesco Natali
Web Developer
Italy Italy
No Biography provided

Comments and Discussions

 
GeneralA 100% .NET solution: PinmemberFrans Bouma11-Dec-02 0:30 
GeneralShell API solution PinmemberBarrett8085-Dec-02 8:37 
GeneralRe: Shell API solution PinsussAnonymous7-Feb-05 5:50 
QuestionRisky? PinmemberMichael Potter4-Dec-02 5:03 
AnswerRe: Risky? PinmemberDavid Stone4-Dec-02 14:54 

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
Web01 | 2.8.1411019.1 | Last Updated 3 Dec 2002
Article Copyright 2002 by Francesco Natali
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid