5,442,164 members and growing! (21,633 online)
Email Password   helpLost your password?
Desktop Development » Selection Controls » General     Intermediate License: The Code Project Open License (CPOL)

Folder Browser component for .NET

By Rama Krishna Vavilala

A component that provides shell folder browsing dialog to .NET applications
C#, Windows, .NET 1.0, .NETVisual Studio, VS.NET2002, Dev

Posted: 5 Mar 2002
Updated: 5 Mar 2002
Views: 206,007
Bookmarked: 59 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
37 votes for this Article.
Popularity: 6.17 Rating: 3.93 out of 5
2 votes, 7.7%
1
3 votes, 11.5%
2
0 votes, 0.0%
3
1 vote, 3.8%
4
20 votes, 76.9%
5

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



Occupation: Architect
Location: United States United States

Other popular Selection Controls articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 57 (Total in Forum: 57) (Refresh)FirstPrevNext
Subject  Author Date 
Generalcan this use in asp.netmembersimiabhilash0:02 11 Jun '08  
GeneralHow to hide the Network Folder?membergust08310:25 15 Nov '07  
GeneralFolder Browser on framework 1.1memberncremaschini1:30 2 Oct '07  
GeneralAdd to the listmembermatt_davis10:09 23 May '07  
QuestionFolder Browser DialogmemberVikram Tapikar1:40 2 Mar '06  
AnswerRe: Folder Browser Dialogmembermatt_davis10:02 31 May '07  
GeneralFolder Browser in Web ProjectmemberJeevan The Wonder0:50 23 Feb '06  
GeneralRe: Folder Browser in Web ProjectmemberRama Krishna Vavilala1:45 23 Feb '06  
GeneralFolder Browser Componentmembermjwaller9:14 1 Feb '06  
GeneralThis code sucksmemberTom Guinther10:08 21 Jan '06  
GeneralRe: This code sucksmemberRama Krishna Vavilala15:55 21 Jan '06  
GeneralWhat is the sense of the NoNewButtonFolder flag?memberJosef Meile8:57 12 Jan '06  
GeneralRe: What is the sense of the NoNewButtonFolder flag?memberJosef Meile9:07 12 Jan '06  
GeneralShellbrowserDialog TextboxmemberMohanPazhanganattu21:45 10 Jan '06  
GeneralButton Text/Title Not VisiblememberAlaranaz18:33 11 Dec '05  
GeneralA fix for SetSelection()memberlujason111:31 7 Dec '05  
AnswerBest Solution: Use OpenFileDialogmembersoftplanner6:14 6 Dec '05  
GeneralRe: Best Solution: Use OpenFileDialogmemberIneffable9:47 1 Aug '06  
GeneralRe: Best Solution: Use OpenFileDialogmemberHamid Qureshi2:25 19 Sep '06  
Generalhow does it work ?memberquietcoder7:51 8 Sep '05  
GeneralOK button textmemberHStrix0:51 2 Mar '05  
GeneralRe: OK button textmemberHStrix20:13 2 Mar '05  
GeneralYou forget somethingmemberYaron Sh22:33 8 Feb '05  
GeneralFew suggestionsmembersmallguy782:07 24 Nov '04  
GeneralListing names of files in a folder in C#sussAnonymous11:08 2 Aug '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 5 Mar 2002
Editor: Chris Maunder
Copyright 2002 by Rama Krishna Vavilala
Everything else Copyright © CodeProject, 1999-2008
Web15 | Advertise on the Code Project