The folder must be created and exist locally whenever the save button is clicked.
I'm guessing you're using EZNamespace (according to the method you supplied) - which internally, it's called after the file dialog is destroyed.
which is poor design by them.
they suggest to create all of your folders while navigating - but i found another way.
The reason it happens, is because when the dialog suppose to close, the path should exist (file dialogs usually are created with an option that says "PATHMUSTEXIST" or "FILEMUSTEXIST" in case of open file dialogs - this cannot be changed after the 3rd party application created the dialog.
i'd suggest to try and implement IObjectWithSite in your custom virtual folder, here's an example:
http://blogs.msdn.com/b/winsdk/archive/2015/03/24/how-to-register-for-file-dialog-notifications-from-shell-namespace-extension.aspx
Just change all "open" to "save" and it will work.
eventually what this does, is that it hooks and registers the IFileDialogEvents for that specific dialog. then you can control some actions around it (for example, use "OnFileOk" instead of your above method, which allows you to cancel the "Ok" with your validations, and also get the actual IShellItem selected.
Whenever "OnFolderChange" is called, you can create your folder, and delete the old one:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb775880(v=vs.85).aspx
Just make sure to not destroy it when the "ok" is eventually clicked, you may delete the folder when the dialog is destroyed (so if user will decide to cancel, you will not have junk folders in your file system).
this should be done here:
if (m_fileOpenDialog != NULL)
{
m_fileOpenDialog->Unadvise(m_cookie);
m_fileOpenDialog->Release();
m_fileOpenDialog = NULL;
m_cookie = 0;
}
just make sure to keep a flag if you pressed the "ok" and not delete the folder.
If the folder exists, the file will be created in the designated file system (you MUST make sure that your virtual file's GetDisplayName will point to the real file system path.
another important note, whenever "OnFileOk" is called, your file will not be there yet (as this runs on the main thread of the 3rd party application). you will have to wait for it to finish writing itself to the file system, then handle it if you want.
As this post is old, if any more concrete examples are needed, just hit with a comment and i'll supply.
Good luck.