Click here to Skip to main content
11,709,581 members (46,372 online)
Click here to Skip to main content

Folder Browser component for .NET

, 5 Mar 2002 CPOL 341.6K 2K 77
Rate this:
Please Sign up or sign in to vote.
A component that provides shell folder browsing dialog to .NET applications
<!-- Download Links -->

Demo Application

Folder browser demo

Dialog generated by settings in the demo application

Folder browser demo

<!-- Add the rest of your HTML here -->

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rama Krishna Vavilala
Architect
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionFolder Browser Dialog for Asp.net web applciations Pin
selllllllllllllll8-Sep-11 2:05
memberselllllllllllllll8-Sep-11 2:05 
Questioncan this use in asp.net Pin
simiabhilash10-Jun-08 23:02
membersimiabhilash10-Jun-08 23:02 
AnswerRe: can this use in asp.net Pin
bibiboule10-Feb-09 3:39
memberbibiboule10-Feb-09 3:39 
QuestionHow to hide the Network Folder? Pin
gust08315-Nov-07 9:25
membergust08315-Nov-07 9:25 
AnswerRe: How to hide the Network Folder? Pin
jmcc2k10-Nov-08 21:31
memberjmcc2k10-Nov-08 21:31 
GeneralFolder Browser on framework 1.1 Pin
ncremaschini2-Oct-07 0:30
memberncremaschini2-Oct-07 0:30 
GeneralAdd to the list Pin
matt_davis23-May-07 9:09
membermatt_davis23-May-07 9:09 
QuestionFolder Browser Dialog Pin
Vikram Tapikar2-Mar-06 0:40
memberVikram Tapikar2-Mar-06 0:40 
AnswerRe: Folder Browser Dialog Pin
matt_davis31-May-07 9:02
membermatt_davis31-May-07 9:02 
GeneralFolder Browser in Web Project Pin
Jeevan The Wonder22-Feb-06 23:50
memberJeevan The Wonder22-Feb-06 23:50 
GeneralRe: Folder Browser in Web Project Pin
Rama Krishna Vavilala23-Feb-06 0:45
memberRama Krishna Vavilala23-Feb-06 0:45 
GeneralRe: Folder Browser in Web Project Pin
selllllllllllllll8-Sep-11 2:03
memberselllllllllllllll8-Sep-11 2:03 
GeneralFolder Browser Component Pin
mjwaller1-Feb-06 8:14
membermjwaller1-Feb-06 8:14 
GeneralThis code sucks Pin
Tom Guinther21-Jan-06 9:08
memberTom Guinther21-Jan-06 9:08 
GeneralRe: This code sucks Pin
Rama Krishna Vavilala21-Jan-06 14:55
memberRama Krishna Vavilala21-Jan-06 14:55 
QuestionWhat is the sense of the NoNewButtonFolder flag? Pin
Josef Meile12-Jan-06 7:57
memberJosef Meile12-Jan-06 7:57 
AnswerRe: What is the sense of the NoNewButtonFolder flag? Pin
Josef Meile12-Jan-06 8:07
memberJosef Meile12-Jan-06 8:07 
GeneralShellbrowserDialog Textbox Pin
MohanPazhanganattu10-Jan-06 20:45
memberMohanPazhanganattu10-Jan-06 20:45 
GeneralButton Text/Title Not Visible Pin
Alaranaz11-Dec-05 17:33
memberAlaranaz11-Dec-05 17:33 
GeneralA fix for SetSelection() Pin
lujason17-Dec-05 10:31
memberlujason17-Dec-05 10:31 
AnswerBest Solution: Use OpenFileDialog Pin
softplanner6-Dec-05 5:14
membersoftplanner6-Dec-05 5:14 
I've looked into this a bit and I've decided that I really hate the FolderBrowserDialog because it doesn't support links or any of the other features of SaveFileDialog or OpenFileDialog.

Fortunately, although its not really a very neat solution, you can get the OpenFileDialog to browse for folders.

The key is setting CheckFileExists to false and setting the Filter to return no file results (by hacking it to look for "no.files"):

OpenFileDialog bob = new OpenFileDialog();
bob.InitialDirectory = txt_DirPath.Text;

bob.Title = "Please choose a folder";
bob.CheckFileExists = false;

bob.FileName = "[Get Folder...]";
bob.Filter = "Folders|no.files";

bob.ShowDialog();

string dir_path = Path.GetDirectoryName(bob.FileName);
if (dir_path != null && dir_path.Length > 0) {
txt_DirPath.Text = dir_path;
}


Note: there is a textbox on the form called "txt_DirPath" that is used to display the folder to which the user browsed.
GeneralRe: Best Solution: Use OpenFileDialog Pin
Ineffable1-Aug-06 8:47
memberIneffable1-Aug-06 8:47 
GeneralRe: Best Solution: Use OpenFileDialog Pin
Hamid Qureshi19-Sep-06 1:25
memberHamid Qureshi19-Sep-06 1:25 
GeneralRe: Best Solution: Use OpenFileDialog Pin
sergio treiger16-May-09 8:38
membersergio treiger16-May-09 8:38 
GeneralRe: Best Solution: Use OpenFileDialog Pin
sergio treiger16-May-09 8:51
membersergio treiger16-May-09 8:51 

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.150819.1 | Last Updated 6 Mar 2002
Article Copyright 2002 by Rama Krishna Vavilala
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid