SaveFileDialog randomly adds file extension

  • Thread starter Thread starter Rock2000
  • Start date Start date
R

Rock2000

I have an app where we turn the AddExtension property of the SaveFileDialog
to true because I always want the extension returned as part of the filename.
But when users start entering filename that would result in multiple dots
(test.a resulting in test.a.mdb) I'm seeing different behaviors on different
systems, with no reasoning that I can see.

On one system, entereing test.a returns test.a instead of test.a.mdb. On my
system test.a returns test.a.mdb, but test.s return test.s. What the heck is
going on here?!? I tried enabling the SupportMultiDottedExtensions option,
but that had no effect.

Thanks. Here's the basic code.

SaveFileDialog save = new SaveFileDialog();
save.CheckPathExists = true;
save.OverwritePrompt = true;
save.AddExtension = true;
save.SupportMultiDottedExtensions = true;
save.DefaultExt = "mdb";
save.Filter = string.Format("{0} (*.mdb)|*.mdb", "Submodel Files");
save.Title = "Select Submodel File to Export";

DialogResult retVal = save.ShowDialog(null);
if(retVal == DialogResult.OK)
MessageBox.Show(save.FileName);
 
I have an app where we turn the AddExtension property of the SaveFileDialog
to true because I always want the extension returned as part of the
filename.
But when users start entering filename that would result in multiple dots
(test.a resulting in test.a.mdb) I'm seeing different behaviors on
different
systems, with no reasoning that I can see.

On one system, entereing test.a returns test.a instead of test.a.mdb. On
my
system test.a returns test.a.mdb, but test.s return test.s. What the heck
is
going on here?!? I tried enabling the SupportMultiDottedExtensions option,
but that had no effect.

While I realize that the dialog's behavior is frustrating and it would be
nice if it worked the way you expect it to, is it really that hard to test
the file name yourself and add the appropriate extension if necessary?
 
No, that's obviously what we ended up doing. But we had a number of bugs
because of what appears to be a bug in Windows, and I'm wondering if it is a
bug or if there is some reasoning to the way it works (since it looks random
to me, I'd say it's a bug). It seems like either the behavior should be
fixed, or the documentation needs to note the special case(s). I'm certain
I'm not the only one who now has bugs in my app because of this issue.
 
Back
Top