Forcing extension in SaveDialog
Is there a straight-forward way of pulling the extension from the Filter so that an extension is always added (ala Word and Notepad). Even with AddExtension = true, a filename with a period in it does not get the extension, e.g., my.file does not save as my.file.txt.
Update The filter index looks like so:
Text (Tab delimited) (*.txt)|*.txt|Unicode text (*.txt)|*.txt|
CSV (Comma delimited) (*.csv)|*.csv|Rich Text Format (*.rtf)|*.rtf|
Web Page (*.htm;*.html)|*.htm;*.html
So indeed, there are some ambiguous extensions (though the first one is intended). When FilterIndex is 1, for example, the intent is that the file has .txt开发者_如何学C at the end, regardless of what is there (except, of course, if it is already txt)
Check the filename returned for your extension. If the last characters (say, 4 for a period plus 3-letter extension) do not match, append the extension to the given filename.
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "MY Project|*.mypi";
精彩评论