Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

I am using SHBrowseForFolder(...) to allow the user to select a folder for saving data to. I want to set it to an initial location dependent on other aspects in the application. I can do this successfully by calling pDesktopFolder->ParseDisplayName(NULL, NULL, olePath, NULL, &defaultPidl, NULL) with the defaultPidl parameter set to the required default location.

It seems that from there the default action is to restrict users from navigating above this point. The need for that is absolutely clear but I don't want to restrict them in that way. Can anyone suggest a way I can lift this restriction but still set the initial location to what I want?

What I have tried:

Extensive online browsing and reading! ;)
Posted
Updated 10-Dec-16 3:44am
v4
Comments
Philippe Mori 10-Dec-16 10:58am    
As suggested in solution 1, I recommend you to use a dialog based upon the OpenFile dialog. And I suggest that you make your own wrapper so that you can select at one location if you want to use SHBrowseForFolder, IFileDialog or customized OpenFileDialog (WinForms).

The rules for this function are clearly documented at BROWSEINFO structure (Windows)[^]. If you do not want this restriction then you need to use a different function. You could use a customised OpeFileDialog as one alternative.

[edit]
The MSDN documentation suggests that you use IFileDialog interface (Windows)[^].
[/edit]
 
Share this answer
 
v2
To do this, you need to specify a callback function in the lpfn member of the BROWSEINFO structure. Set the initial folder to the desktop (or the highest level you want allowed) at first. Once the dialog has been initialised, you can send a BFFM_SETSELECTION message to the dialog with the folder you want selected in the LPARAM. See BFFCALLBACK function pointer (Windows)[^] for detailed info on how to do all this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900