I've the following C# code, which is using the SaveFileDialog and set's the AddExtension property to true
:
var dialog = new SaveFileDialog();
dialog.AddExtension = true;
dialog.DefaultExt = "txt";
dialog.Filter = "Text files (*.txt)|*.txt|XML files (*.xml)|*.xml";
dialog.OverwritePrompt = true;
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
label1.Text = dialog.FileName;
}
And I've tested the following combination of File name
and Save as type
of the dialog.
File name | Save as type | label1.Text | What I expect
----------------+----------------+----------------+----------------
test1 | *.txt | test1.txt | test1.txt
test2.txt | *.txt | test2.txt | test2.txt
test3.abc | *.txt | test3.abc.txt | test3.abc.txt
test4 | *.xml | test4.xml | test4.xml
test5.xml | *.xml | test5.xml | test5.xml
test6.abc | *.xml | test6.abc.xml | test6.abc.xml
----------------+----------------+----------------+----------------
test7.xml | *.txt | test7.xml | test7.xml.txt
test8.bmp | *.txt | test8.bmp | test8.bmp.txt
test9.bmp | *.xml | test9.bmp | test9.bmp.xml
For the last three lines of the above table I would expect a double extension like it does for the unknown abc
extension. Applications like Microsoft Word behave like that (they always add the double extension if the Save as type
doesn't match the extension given by the user in File name
).
Is there a way to change that?
I don't want to do it after the dialog is closed because then I've to check again if the file already exists and if the file name is not too long.
Update:
I've tested it as well with the MONO framework using Ubuntu 18.04. In that case a double extension is never created, e.g.: test3.abc
using MONO vs test3.abc.txt
using .NET Framework 4.5 (Windows 10).
FilterIndex
property to decide if I should store it astxt
orxml
file and not the extension of theFileName
property. – PinebrookSave type as
) then I would expect a double extension, like*.abc.txt
. It adds a double extension to all unknown (for the system) extensions likeabc
and it doesn't add a double extension for all known (for the system) extensions likebmp
. But I cannot expect from the user that he knows which extensions the system knows. – PinebrookCheckFileExists=true
property doesn't make sense forSaveFileDialog
. I don't want to see a warning if the file doesn't exist. – Pinebrook