Click here to Skip to main content
15,860,943 members
Articles / Programming Languages / C#
Article

Folder Browser component for .NET

Rate me:
Please Sign up or sign in to vote.
4.63/5 (27 votes)
5 Mar 2002CPOL2 min read 426K   2.8K   80   64
A component that provides shell folder browsing dialog to .NET applications

Demo Application

Folder browser demo

Dialog generated by settings in the demo application

Folder browser demo

Introduction

ShellFolderBrowser
is a component that makes it possible to use shell's folder browsing dialog for .NET applications. It can be used in the same way as
OpenFileDialog
and SaveFileDialog components which are available from the framework SDK. The component makes use of SHBrowseForFolder function and demonstrates various aspects of interoperability of managed and unmanaged code like passing delegates function pointers, passing structures and strings.

It is quite simple to use the component. You can place it on the toolbox and drag it to the form. You can set the desired properties in the component in the property grid as shown :-


Folder browser demo

In order to display the dialog all that needs to be done is to call the

ShowDialog
method as

folderBrowser1.ShowDialog();

Here is a brief description of the component. For detailed description see the documentation of SHBrowseForFolder.

Properties

BrowseFlagsSets the flags that control the behaviour of the dialog
FolderDisplayNameThe display name of the folder selected by the user
FolderPathThe folder path that was selected
TitleString that is displayed above the tree view control in the dialog box. This string can be used to specify instructions to the user. Can only be modified if the dalog is not currently displayed.

Methods

EnableOKButtonEnables or disables the ok button in the dialog
SetExpandedExpand a path in the folder
SetOkButtonTextSets the text of the OK button in the dialog
SetSelectionSets the selection the text specified
SetStatusTextSets the text of the staus area of the folder dialog
ShowDialogShows the dialog

Events

InitializedFired when the dialog is initialized (when BFFM_INITIALIZED is send to the
BrowseCallback
function)
IUnknownObtainedShell provides an IUnknown through this event. For details see documentation of
SHBrowseForFolder
(when BFFM_INITIALIZED is send to the BrowseCallback function)
SelChangedFired when selection changes (when BFFM_INITIALIZED is send to the
BrowseCallback
function)
ValidateFailedFired when validation of text typed by user fails (when BFFM_INITIALIZED is send to the BrowseCallback function)

BrowseFlags 

BrowseFlags is an enumeration with Flags attribute set and can be a combination of any of the following values :-

ReturnOnlyFSDirs

Same as BIF_RETURNONLYFSDIRS

DontGoBelowDomain

Same as BIF_DONTGOBELOWDOMAIN

ShowStatusText

Same as BIF_STATUSTEXT

ReturnFSancestors

Same as BIF_RETURNFSANCESTORS

EditBox

Same as BIF_EDITBOX

Validate

Same as BIF_VALIDATE

NewDialogStyle

Same as BIF_NEWDIALOGSTYLE

BrowseIncludeURLs

Same as BIF_BROWSEINCLUDEURLS

AddUsageHint

Same as BIF_UAHINT

NoNewFolderButton

Same as BIF_NONEWFOLDERBUTTON

BrowseForComputer

Same as BIF_BROWSEFORCOMPUTER

BrowseForPrinter

Same as BIF_BROWSEFORPRINTER

IncludeFiles

Same as BIF_BROWSEINCLUDEFILES

ShowShareable

Same as BIF_SHAREABLE

License

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


Written By
Architect
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionFolder Browser Dialog for Asp.net web applciations Pin
selllllllllllllll8-Sep-11 2:05
selllllllllllllll8-Sep-11 2:05 
Questioncan this use in asp.net Pin
simiabhilash10-Jun-08 23:02
simiabhilash10-Jun-08 23:02 
AnswerRe: can this use in asp.net Pin
bibiboule10-Feb-09 3:39
bibiboule10-Feb-09 3:39 
QuestionHow to hide the Network Folder? Pin
gust08315-Nov-07 9:25
gust08315-Nov-07 9:25 
AnswerRe: How to hide the Network Folder? Pin
jmcc2k10-Nov-08 21:31
jmcc2k10-Nov-08 21:31 
GeneralFolder Browser on framework 1.1 Pin
ncremaschini2-Oct-07 0:30
ncremaschini2-Oct-07 0:30 
GeneralAdd to the list Pin
matt_davis23-May-07 9:09
matt_davis23-May-07 9:09 
QuestionFolder Browser Dialog Pin
Vikram Tapikar2-Mar-06 0:40
Vikram Tapikar2-Mar-06 0:40 
AnswerRe: Folder Browser Dialog Pin
matt_davis31-May-07 9:02
matt_davis31-May-07 9:02 
GeneralFolder Browser in Web Project Pin
Jeevan The Wonder22-Feb-06 23:50
Jeevan The Wonder22-Feb-06 23:50 
GeneralRe: Folder Browser in Web Project Pin
Rama Krishna Vavilala23-Feb-06 0:45
Rama Krishna Vavilala23-Feb-06 0:45 
GeneralRe: Folder Browser in Web Project Pin
selllllllllllllll8-Sep-11 2:03
selllllllllllllll8-Sep-11 2:03 
GeneralFolder Browser Component Pin
mjwaller1-Feb-06 8:14
mjwaller1-Feb-06 8:14 
GeneralThis code sucks Pin
Tom Guinther21-Jan-06 9:08
Tom Guinther21-Jan-06 9:08 
GeneralRe: This code sucks Pin
Rama Krishna Vavilala21-Jan-06 14:55
Rama Krishna Vavilala21-Jan-06 14:55 
QuestionWhat is the sense of the NoNewButtonFolder flag? Pin
Josef Meile12-Jan-06 7:57
Josef Meile12-Jan-06 7:57 
AnswerRe: What is the sense of the NoNewButtonFolder flag? Pin
Josef Meile12-Jan-06 8:07
Josef Meile12-Jan-06 8:07 
GeneralShellbrowserDialog Textbox Pin
MohanPazhanganattu10-Jan-06 20:45
MohanPazhanganattu10-Jan-06 20:45 
GeneralButton Text/Title Not Visible Pin
Alaranaz11-Dec-05 17:33
Alaranaz11-Dec-05 17:33 
GeneralA fix for SetSelection() Pin
lujason17-Dec-05 10:31
lujason17-Dec-05 10:31 
AnswerBest Solution: Use OpenFileDialog Pin
softplanner6-Dec-05 5:14
softplanner6-Dec-05 5:14 
GeneralRe: Best Solution: Use OpenFileDialog Pin
Ineffable1-Aug-06 8:47
Ineffable1-Aug-06 8:47 
GeneralRe: Best Solution: Use OpenFileDialog Pin
Hamid Qureshi19-Sep-06 1:25
Hamid Qureshi19-Sep-06 1:25 
GeneralRe: Best Solution: Use OpenFileDialog Pin
sergio treiger16-May-09 8:38
sergio treiger16-May-09 8:38 
I've downloaded half a dozen solutions for this problem, each one more complicated than the previous one.

And then I found this one. It's simple and works fine!. Less is more!!
GeneralRe: Best Solution: Use OpenFileDialog Pin
sergio treiger16-May-09 8:51
sergio treiger16-May-09 8:51 

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.