N
Neville
SaveFileDialog's ShowDialog method returns
DialogResult.Cancel when a user clicks the "Yes" button
when asked whether to overwrite an existing file. Is
this a known SaveFileDialogBug?
I'm running version 1.1.4322.573 of the .Net Framework
on "Windows XP Professional 2002 Service Pack 1".
Sample code illustrating the problem is shown below. The
contents of foo.txt are never "replacement text".
---------------------------------------------------
using System;
using System.IO;
using System.Windows.Forms;
namespace Frustration
{
class Sample
{
[STAThread]
static void Main(string[] args)
{
SaveFile ("foo.txt", "original text");
SaveFile ("foo.txt", "replacement text");
}
// Shows a SaveFileDialog prompting the user to
// save the specified file. Attempts to write
// the specified text
// to the file.
static void SaveFile (string fileName,
string text)
{
SaveFileDialog saveFileDialog =
new SaveFileDialog();
saveFileDialog.FileName = "foo.txt";
// OverwritePrompt is true by default, but I
// explicitly set it for clarity.
saveFileDialog.OverwritePrompt = true;
if (saveFileDialog.ShowDialog() !=
DialogResult.Cancel)
{
StreamWriter writer = null;
try
{
writer = new StreamWriter
(saveFileDialog.OpenFile());
writer.Write (text);
writer.Flush();
}
finally
{
writer.Close();
}
} // !Cancel
} // SaveFile
} // Sample
} // Frustration
DialogResult.Cancel when a user clicks the "Yes" button
when asked whether to overwrite an existing file. Is
this a known SaveFileDialogBug?
I'm running version 1.1.4322.573 of the .Net Framework
on "Windows XP Professional 2002 Service Pack 1".
Sample code illustrating the problem is shown below. The
contents of foo.txt are never "replacement text".
---------------------------------------------------
using System;
using System.IO;
using System.Windows.Forms;
namespace Frustration
{
class Sample
{
[STAThread]
static void Main(string[] args)
{
SaveFile ("foo.txt", "original text");
SaveFile ("foo.txt", "replacement text");
}
// Shows a SaveFileDialog prompting the user to
// save the specified file. Attempts to write
// the specified text
// to the file.
static void SaveFile (string fileName,
string text)
{
SaveFileDialog saveFileDialog =
new SaveFileDialog();
saveFileDialog.FileName = "foo.txt";
// OverwritePrompt is true by default, but I
// explicitly set it for clarity.
saveFileDialog.OverwritePrompt = true;
if (saveFileDialog.ShowDialog() !=
DialogResult.Cancel)
{
StreamWriter writer = null;
try
{
writer = new StreamWriter
(saveFileDialog.OpenFile());
writer.Write (text);
writer.Flush();
}
finally
{
writer.Close();
}
} // !Cancel
} // SaveFile
} // Sample
} // Frustration