SaveFileDialog filter
-
Hello all. I'm trying to allow a user to save a text file and only a text file. My filter is "Text files (*txt)|*txt" This seems to be set up fine but when I save a file, I can save as .doc. This shouldn't happen, at least that's what I thought. Where am I going wrong?
-
Hello all. I'm trying to allow a user to save a text file and only a text file. My filter is "Text files (*txt)|*txt" This seems to be set up fine but when I save a file, I can save as .doc. This shouldn't happen, at least that's what I thought. Where am I going wrong?
You're making the assumption that the SaveAs dialog restricts the extension the user can use. Wrong. This only filter the filenames listed in the dialog box. You're code has to make sure the extension is correct, and fix it if it's not, after the user clicks OK and before you open the stream to start writing your data.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008