Click here to Skip to main content
15,867,991 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 426.3K   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

 
GeneralRe: Setting the initial folder Pin
Greg Finzer25-Aug-02 13:10
Greg Finzer25-Aug-02 13:10 
GeneralRe: Setting the initial folder Pin
Purve27-Jan-03 0:41
Purve27-Jan-03 0:41 
GeneralRe: Setting the initial folder Pin
Jeff Ellerbee26-May-04 17:55
Jeff Ellerbee26-May-04 17:55 
GeneralCreating a component that does the same - a TreeView component Pin
Ruvan20-Apr-02 13:47
Ruvan20-Apr-02 13:47 
GeneralRe: Creating a component that does the same - a TreeView component Pin
chriskoiak8-Jan-04 2:04
chriskoiak8-Jan-04 2:04 
GeneralRe: Creating a component that does the same - a TreeView component Pin
jmcc2k11-Nov-08 17:46
jmcc2k11-Nov-08 17:46 
GeneralCouldn't set selected Pin
6-Mar-02 16:09
suss6-Mar-02 16:09 
GeneralRe: Couldn't set selected Pin
Rama Krishna Vavilala8-Mar-02 7:05
Rama Krishna Vavilala8-Mar-02 7:05 
GeneralRe: Couldn't set selected Pin
JDutch2-Jul-02 5:05
JDutch2-Jul-02 5:05 
Generalnot very .net'ish Pin
6-Mar-02 7:36
suss6-Mar-02 7:36 
GeneralRe: not very .net'ish Pin
Rama Krishna Vavilala6-Mar-02 8:09
Rama Krishna Vavilala6-Mar-02 8:09 
GeneralRe: not very .net'ish Pin
6-Mar-02 9:40
suss6-Mar-02 9:40 
GeneralRe: not very .net'ish Pin
Rama Krishna Vavilala6-Mar-02 9:43
Rama Krishna Vavilala6-Mar-02 9:43 
GeneralRe: not very .net'ish Pin
Christopher Lord24-Oct-02 16:25
Christopher Lord24-Oct-02 16:25 

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.