4

I'm trying to create a dialog to select a new folder to save files into. The IFileOpenDialog class works great except that it won't allow a new folder to be picked.

I.e. "Folder: C:\existings\new-folder" in the bottom of the dialog pops up the following message:

new-folder
Path does not exist.
Check the path and try again.

Here's the code I've got:

IFileDialog* fileDialog
CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, 
    IID_PPV_ARGS(&fileDialog));

DWORD options;
fileDialog->GetOptions(&options);

options &= ~FOS_FILEMUSTEXIST;  
options &= ~FOS_PATHMUSTEXIST;
fileDialog->SetOptions(options | FOS_PICKFOLDERS);

fileDialog->Show(parentWindow);

Any pointers or hacks would be appreciated! Thanks!


To quote Michael from this other question:

[To head off some comments, the SHBrowseForFolder API still exists, but is still not an acceptable solution for our UI deciders.]

The same applies here...

Community
  • 1
  • 1
Luke Quinane
  • 16,447
  • 13
  • 69
  • 88
  • 1
    This begs the question of why you're using an open dialog to select where to save something... – Deanna Dec 02 '11 at 09:38
  • Deanna, I'm trying to replace a Java select file dialog with a native version so it has to match the original behaviour (unfortunately that means the folder pick dialog is out). With the Java dialog you can browse to a folder and type in the name for a new folder to create (Imaging an archive application where you want to pick a new folder to save a bunch of files into). Trying to do that with IFileOpenDialog fails if FOS_PICKFOLDERS is used. – Luke Quinane Dec 18 '11 at 22:22
  • Can't they just click the native "create folder" button and select it? – Deanna Dec 19 '11 at 00:40
  • That's possible, its just not as nice ;-) Imagine if every time you wanted to save a file you had to click "create file" then select it. – Luke Quinane Dec 19 '11 at 01:10
  • @Deanna It's like a **Save As** dialog. The user is trying to specify where something **will** go; not where something **is**. – Ian Boyd Jun 19 '20 at 18:59

2 Answers2

2

I think you want to use CLSID_FileSaveDialog instead of CLSID_FileOpenDialog. And possibly make use of IFileSaveDialog in addition to the base class IFileDialog.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
selbie
  • 100,020
  • 15
  • 103
  • 173
  • 2
    It looks like the save dialog no longer supports FOS_PICKFOLDERS: http://stackoverflow.com/questions/1626993/ifilesavedialog-choosing-folders-in-windows-7 – Luke Quinane Dec 01 '11 at 21:19
  • 2
    It was never supported in `IFileSaveDialog` to begin with, as it is an `IFileOpenDialog` flag. – Remy Lebeau Dec 01 '11 at 21:44
1

As you're selecting a folder, you could use the folder picker dialog. This, with the right flags, has a "create" button at the bottom and a text entry allowing you to specifiy a non existant path.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Deanna
  • 23,876
  • 7
  • 71
  • 156
  • 3
    On [MSDN](http://msdn.microsoft.com/en-us/library/bb762115%28VS.85%29.aspx) it sounds like SHBrowseForFolder is discouraged for new apps: `For Windows Vista or later, it is recommended that you use IFileDialog with the FOS_PICKFOLDERS option rather than the SHBrowseForFolder function. This uses the Open Files dialog in pick folders mode and is the preferred implementation.` – Luke Quinane Jan 09 '12 at 23:02