Click here to Skip to main content
Licence CPOL
First Posted 5 Mar 2002
Views 290,769
Bookmarked 76 times

Folder Browser component for .NET

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

About the Author

Rama Krishna Vavilala

Architect

United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionFolder Browser Dialog for Asp.net web applciations Pinmemberselllllllllllllll2:05 8 Sep '11  
Questioncan this use in asp.net Pinmembersimiabhilash23:02 10 Jun '08  
AnswerRe: can this use in asp.net Pinmemberbibiboule3:39 10 Feb '09  
QuestionHow to hide the Network Folder? Pinmembergust0839:25 15 Nov '07  
AnswerRe: How to hide the Network Folder? Pinmemberjmcc2k21:31 10 Nov '08  
GeneralFolder Browser on framework 1.1 Pinmemberncremaschini0:30 2 Oct '07  
GeneralAdd to the list Pinmembermatt_davis9:09 23 May '07  
QuestionFolder Browser Dialog PinmemberVikram Tapikar0:40 2 Mar '06  
AnswerRe: Folder Browser Dialog Pinmembermatt_davis9:02 31 May '07  
GeneralFolder Browser in Web Project PinmemberJeevan The Wonder23:50 22 Feb '06  
GeneralRe: Folder Browser in Web Project PinmemberRama Krishna Vavilala0:45 23 Feb '06  
This is a windows forms control and cannot be used in a web project.Confused | :confused:
 


Member in good standing - the great cult of Firefox at CP
GeneralRe: Folder Browser in Web Project Pinmemberselllllllllllllll2:03 8 Sep '11  
GeneralFolder Browser Component Pinmembermjwaller8:14 1 Feb '06  
GeneralThis code sucks PinmemberTom Guinther9:08 21 Jan '06  
GeneralRe: This code sucks PinmemberRama Krishna Vavilala14:55 21 Jan '06  
QuestionWhat is the sense of the NoNewButtonFolder flag? PinmemberJosef Meile7:57 12 Jan '06  
AnswerRe: What is the sense of the NoNewButtonFolder flag? PinmemberJosef Meile8:07 12 Jan '06  
GeneralShellbrowserDialog Textbox PinmemberMohanPazhanganattu20:45 10 Jan '06  
GeneralButton Text/Title Not Visible PinmemberAlaranaz17:33 11 Dec '05  
GeneralA fix for SetSelection() Pinmemberlujason110:31 7 Dec '05  
AnswerBest Solution: Use OpenFileDialog Pinmembersoftplanner5:14 6 Dec '05  
GeneralRe: Best Solution: Use OpenFileDialog PinmemberIneffable8:47 1 Aug '06  
GeneralRe: Best Solution: Use OpenFileDialog PinmemberHamid Qureshi1:25 19 Sep '06  
GeneralRe: Best Solution: Use OpenFileDialog Pinmembersergio treiger8:38 16 May '09  
GeneralRe: Best Solution: Use OpenFileDialog Pinmembersergio treiger8:51 16 May '09  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 6 Mar 2002
Article Copyright 2002 by Rama Krishna Vavilala
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid