FileChooser::browseForfiletoSave question



When using “browseForFiletoSave”, with the info box “warning if overwriting”,
I get something bad.

I want to save XML files, but without asking the user to enter the extension : he saves for instance “untitled” and I write “untitled.xml”

In this case, the “overwrite” warning does not raise, cause “untitled” and previous “untitled.xml” are compared, and not equal.

Do you know how to avoid it ?


[code]void MainMenuBar::enregistrerSous(){
FileChooser * saveAsFC = new FileChooser(T(“Save as”), File::getSpecialLocation(File::userDesktopDirectory), T("*.xml"), true);
if(saveAsFC->browseForFileToSave(true/warnaboutOverwriting/)) {




void MainMenuBar::sauvegarderXml(File _xml) {

File* savedFile = new File(_xml.getFullPathName()+String(".xml"));
cout << "Saved file : " << (string)(savedFile->getFullPathName()) << endl;
jassert(savedFile->getFileExtension() == String(".xml"));

if (savedFile == 0)



Unfortunately the overwrite warning flag just gets passed to the OS’s dialog box, so we have no control over how the dialog decides to do it.

It’s only a couple of lines of code to add your own warning box after you’ve changed the extension though.


Can you give an example plz ?


You want an example of how to check whether a file exists, and pop up a dialog box if it does…?


JUCE’s behaviour is really weird indeed. For instance I want to save a called XXX with default extension .YYY, I type no extension in my save dialog (so the default .YYY should be added automatically), and if there’s a file XXX (without any extension) on the disk, then I’m asked by Windows if I want to overwrite this file, which doesn’t make any sense at all, because I don’t want to overwrite XXX, but I want to overwrite XXX.YYY!

I think this is a JUCE bug. In fact, the extension is not added to the file.
Why? Because lpstrDefExt is not set by JUCE.

Pointer to a buffer that contains the default extension. GetOpenFileName and GetSaveFileName append this extension to the file name if the user fails to type an extension. This string can be any length, but only the first three characters are appended. The string should not contain a period (.). If this member is NULL and the user fails to type an extension, no extension is appended.


I agree that as of now the feature is not very useful, I also had to disable the overwrite check of the filechooser, manually add the extension after calling browseForFileToSave, and then check if the file already exists.

Not a big deal, but the warnAboutOverwriting is confusing.