Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1620
  • Last Modified:

Browse for Folder in C#

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.
0
hilson
Asked:
hilson
3 Solutions
 
cocojohnCommented:
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";
dlg.ShowDialog();
0
 
hilsonAuthor Commented:
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.
0
 
AlexFMCommented:
http://www.codeproject.com/csharp/csdoesshell1.asp

Section 2: ShellBrowseForFolderDialog - A Class that Wraps a Dialog

RootType and RootPath properties of this class allow to set initial directory.
0
Industry Leaders: 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!

 
hilsonAuthor Commented:
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?
0
 
Volcano_88101Commented:
You should be able to use the

SHBrowseForFolder

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
0
 
daytrip00Commented:
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
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now