[ACCEPTED]-Change file extension when user changes Save As Type in SaveFileDialog-windows-xp

Accepted answer
Score: 11

I just tested and it works just fine.
I 7 did this:

        SaveFileDialog sfd = new SaveFileDialog();

        sfd.FileName = "untitled";
        sfd.Filter = "Text (*.txt)|*.txt|Word Doc (*.doc)|*.doc";

And it automatically changes 6 the suggested save name depending on the 5 filter I choose.
I used the .NET 2.0 framework.
But 4 I'm on Windows 7, which I think matters, since 3 you see the system's file-save dialog, and 2 the way it's implemented is what matters 1 here.

Score: 2

Adding DefaultExt and AddExtension will 2 give you the behaviour you're looking for. Simialr 1 to question/answer provided here: https://stackoverflow.com/a/1213353/101971

        var saveFileDialog = new SaveFileDialog
                                     Filter = "Foo (*.foo)|*.foo|Bar (*.bar)|*.bar",
                                     DefaultExt = "foo",
                                     AddExtension = true
Score: 1

When you go to actually save the file you 4 can get the file name from the dialog box, then 3 perform the necessary string manipulation 2 from there. The file name is a member of 1 the instance of the SaveFileDialog

Score: 0

You may do: savefiledialog1.AddExtension 1 = True

More Related questions