When using the SaveFileDialog (in VB .NET), is there a way, while the dialog is displayed, to automatically update the displayed "File name:" extension when "Save as type:" changes
As an example, in Microsoft Word, while the save dialog is displayed, if you change the "Save as type:", i.e., from ".doc" to ".txt", the dialog automatically changes the "File name:" extension to the selected type (while the dialog is dispayed, before clicking the Save button). Furthermore (again in MS Word), when the "File name:" textbox loses focus, if an extension is not specified, the dialog will automatically append the extension for the selected type, i.e., if the "File name:" text box contains only the text "Doc1" (with no extension) and the selected "Save as type:" is "Word Document (*.doc)", when the textbox loses focus, the dialog will automatically append ".doc" to the value in the "File name:" textbox, i.e., "Doc1.doc".
I have been unable to figure out how to mimic this behavior using the .NET SaveFileDialog If the user is attempting to save a file and changes the "Save as type:" value but does not change the extension in the "File name:" textbox (or vice-versa), after they click the Save button, I have to guess which is the extension/type they intended.
If the SaveFileDialog does not support this functionality, is there another component that does
Any information or suggestions would be greatly apprecitated.

SaveFileDialog - Automatically update displayed Extension when Save as Type changes
andrewfranchuk
In regards to detecting when the user changes the filter selection and/or loses focus you can do it using a template hook that the common dialogs support. Alas this is not supported in .NET so you will have to call out to unmanaged code to set up the hook. Ideally you would be able to override the OwnerWndProc method that gets called but alas the class is sealed so you can't.
In regards to knowing what filter was selected you can use the FilterIndex property. When the dialog returns the currently selected filter will be indicated by this property. You can compare that to the file exist as needed to determine what to do next. Note that this value is 1-based.
Michael Taylor - 2/7/06
zpustc
Alas, indeed =(. I'm surprised that relatively standard behavior such as this (and which Microsoft has implemented in Office, Visual Studio, and Internet Explorer) is not supported by .NET.
I've got the FilterIndex code working OK (thanks for the information). I am defaulting the filename without an extension. If the user manually enters an extension, I use this as the file type/extension; otherwise, I use the extension for the selected FilterIndex. It's far from ideal, but I've resinged myself to let it be acceptable. I don't think I'm ready to think about hooks, OwnerWndProcs, and unmanaged code yet (not that it would make a difference since it's sealed, as you said), so I guess this will have to do.
Thank you so much for your response and information!!
jmweekes - 02/07/06