Browse for Folder in C#

Posted on 2003-02-25
Medium Priority
Last Modified: 2007-12-19
Has anyone managed to use BrowseForFolder in C# WITH initial folder selection.  I can get the dialog to come up in a number of different ways (using old API / new .Net (framework support)  code) however i cant get the initial folder selection working.  I've implemented a callback for the purposes of sending the BFFM_SETSELECTIONA message to the dialog but it seems to have no effect. (I know I'm sending to the dialog because I can send BFFM_ENABLEOK to enable / disable the OK button).  The problem seems to lie with translating my path string into the lparam parameter for BFFM_SETSELECTIONA.
Question by:hilson
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8015482
If you use a subclass of System.Windows.Forms.FileDialog,
you have to set the InitialDirectory property before showing the dialog:

OpenFileDialog dlg = new OpenFileDialog();
dlg.InitialDirectory = "C:\anywhere";

Author Comment

ID: 8015631
Thanks - but i dont want a file open dialog - i am asking the user to select a folder - so i just want the browseforfolder type dialog in which the user selects a folder only - they dont open a file in a specified folder.
LVL 48

Accepted Solution

AlexFM earned 136 total points
ID: 8015883

Section 2: ShellBrowseForFolderDialog - A Class that Wraps a Dialog

RootType and RootPath properties of this class allow to set initial directory.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 8016901
Thanks for that - I had high hopes until I realised that the method it uses to take a folder path and convert it into a PIDL (for use by the callback fn) is only available in version 6.0 of shell32.dll - which is for windows XP.  i wonder whether this version works on earlier o/s's?

Assisted Solution

Volcano_88101 earned 132 total points
ID: 8022447
You should be able to use the


This function is existen in Windows 95 and NT and above and requires Shell32.dll 4.0 and above. Most of the Shell API Functionality is added in the latest IE so you would just make sure that Their IE version was upto date

Assisted Solution

daytrip00 earned 132 total points
ID: 8026833
I had the same problem.  There is an "Unsupported" way, using a dialog that, I've heard, you aren't supposed to use.  But nonetheless, it's always worked for me:

use the System.Windows.Forms.Design.FolderNameEditor.FolderBrowser.

With that, you just set the description, and call .ShowDialog().

HTH, martin

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question