Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My code hasn't changed in any significant way, but for some reason my save file dialog now flickers open, then closes and the show dialog result returned is false. It was working flawlessly for some time, but now it is doing this. Has anyone else seen something like this?

C#
internal string BrowseForSaveAsDoc()
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.CheckPathExists = true;
            dlg.CheckFileExists = false;
            dlg.DefaultExt = ".docx";
            dlg.AddExtension = true;
            dlg.Filter = "Word Documents (*.docx)|*.docx";
            var res = dlg.ShowDialog();
            if (res == true)
                return dlg.FileName;
            return "";
        }

I instantly see res as false when I set a breakpoint on the if statement. It was working flawlessly just the other day. Is there something funky that happened to my computer or something?

UPDATE:
Solved by OP himself. Posted as one of the answers.
Posted
Updated 22-Apr-11 18:30pm
v2

Ok I figured out what is happening. The button that executes the show modal actions is inside a wpf popup control. I modified the popup to StaysOpen="false". So the popup hides the moment it loses focus (when the modal shows up) and thus the context that called the modal is killed so it just cancels itself out.
 
Share this answer
 
A side note: Don't write return "", use string.Empty (or null if you wish). Avoid immediate constants (such as "") in all cases.

—SA
 
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