Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Folder Browser component for .NET

0.00/5 (No votes)
5 Mar 2002 2  
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

BrowseFlags Sets the flags that control the behaviour of the dialog
FolderDisplayName The display name of the folder selected by the user
FolderPath The folder path that was selected
Title String 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

EnableOKButton Enables or disables the ok button in the dialog
SetExpanded Expand a path in the folder
SetOkButtonText Sets the text of the OK button in the dialog
SetSelection Sets the selection the text specified
SetStatusText Sets the text of the staus area of the folder dialog
ShowDialog Shows the dialog

Events

Initialized Fired when the dialog is initialized (when BFFM_INITIALIZED is send to the BrowseCallback function)
IUnknownObtained Shell provides an IUnknown through this event. For details see documentation of SHBrowseForFolder (when BFFM_INITIALIZED is send to the BrowseCallback function)
SelChanged Fired when selection changes (when BFFM_INITIALIZED is send to the BrowseCallback function)
ValidateFailed Fired 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 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