Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing extension in SaveDialog

Tags:

c#

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 at the end, regardless of what is there (except, of course, if it is already txt)

like image 716
tofutim Avatar asked Jul 26 '11 23:07

tofutim


1 Answers

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.

like image 182
D.N. Avatar answered Sep 25 '22 00:09

D.N.