Shawn, This issue is very strange. I tried your code, and posted my result on your blog. However, using the exact same configuration (WinXP Pro, Framework 1.0) I get no problem by following Russell's test. I even tried overwriting that file that you created (sfddebug). The issue seems to be the parameter to ShowDialog. Converting your code into the following does the trick.
HTH, Jason Hagar using System; using System.IO; using System.Windows.Forms; public class MainModule : Form { [STAThread] static void Main() { Application.Run(new MainModule()); } public MainModule() { // Create a dummy file in the cwd. if (!File.Exists("sfdbug.txt")) { using (StreamWriter sw = File.CreateText("sfdbug.txt")) { sw.WriteLine("Overwrite me!"); } } // Now to demonstrate the bug -- when prompted, choose to overwrite sfdbug.txt! SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "Try to overwrite sfdbug.txt -- I dare you!"; sfd.InitialDirectory = Environment.CurrentDirectory; sfd.DefaultExt = "txt"; sfd.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; // Uncomment the following line, and all is ok. // sfd.OverwritePrompt = false; // Here's the bug: dr==Cancel, even when we answer 'yes' to the // overwrite prompt!? //DialogResult dr = sfd.ShowDialog(); MessageBox.Show(sfd.ShowDialog(this).ToString()); //MessageBox.Show("You pressed: "+dr.ToString()); // Here's the workaround: ignore the DialogResult, and simply look at // the SFD's FileNames property (it'll be a zero-length array, if the // user chose not to overwrite the existing file. //MessageBox.Show(String.Format("And SFD returned {0} filenames", sfd.FileNames.Length)); } } -----Original Message----- From: Moderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Shawn A. Van Ness Sent: Wednesday, July 23, 2003 1:09 PM To: [EMAIL PROTECTED] Subject: Re: [ADVANCED-DOTNET] Bug in SaveFileDialog.OverwritePrompt? Umm... did you actually try to overwrite a file, Russel? What OS? I'm now officially not the only person to repro this! http://weblogs.asp.net/savanness/posts/10446.aspx (Thanks Scott...) I've repro'd this bug on three flavors of XP -- Home, Pro, and Tablet -- all of the machines' shell settings in various degrees of messiness. I haven't yet tried to repro on a perfectly clean, freshly formatted machine. Or on W2k3 Server, for that matter. The workaround (looking at SFD.FileNames.Length) is trivial -- my goal here is hopefully someone from MS will investigate this, and raid the bug. One never knows when these kinds of things may be symptoms of some larger bug...? Cheers, -S On Mon, 14 Jul 2003 15:07:56 -0700, Russell McClure <[EMAIL PROTECTED]> wrote: >Shawn, > >I couldn't reproduce it. I dropped a Save Dialog onto a Form and used the >following code: > >MessageBox.Show(saveFileDialog1.ShowDialog(this).ToString()); > >which displayed 'OK' unless I pressed the cancel button in which case it >displayed 'Cancel'. The value of the OverwritePrompt didn't have any >effect on my end result. > >Russ > > >At 02:45 PM 7/14/2003 -0700, you wrote: >>I got no response on this post at dotnet-winforms... thought I'd escalate >>it here, hoping somebody can confirm this as a bug. >> >>Alternatively, if you try to repro and can't, please let me know that >>too. It may be a strange symptom of some obscure shell setting I've got >>configured, or something. Crazier things have happened... you never know. >> >>-S >> >>----- Original Message ----- >>From: "Shawn A. Van Ness" <[EMAIL PROTECTED]> >>Sent: Friday, July 04, 2003 06:39 >>Subject: Bug in SaveFileDialog.OverwritePrompt? >> >>.NET v1.1... >> >>When SaveFileDialog.OverwritePrompt is set to true (the default), the >>DialogResult returned by SaveFileDialog.ShowDialog is "Cancel", when the >>user chooses "yes" to overwrite an existing file. >> >>http://www.arithex.com/temp/SFDbug.cs.html >> >>Turning off the OverwritePrompt feature (uncomment the line of code, in >>the above sample) returns "OK" when an existing file is chosen. >> >>Am I missing something? I found one reference to this in the archives, >>from way way back in v1.0 days, but nobody claimed to be able to repro. >>http://discuss.develop.com/archives/wa.exe?A2=ind0206A&L=DOTNET-CLR&P=690 >> >>-S