Can I Count on Common File Dialog to give me a Valid Filetype (based on Filter)
Can I count on the Common File Dialogs eg. OpenFileDialog, SaveFileDialog and their properties eg. Filter, CheckFileExists, CheckPathExists to give me a valid file? Or must I check again?
I guess if I were to check again, I will use System.IO.Path.GetExtension
? I wonder what h开发者_如何学Pythonappens if an invalid file is provided (eg. rename a .txt to .exe)
You can be reasonably sure that, with the settings you are talking about, the returned file will exist with the name given at the time the file was selected; however, there's nothing to prevent that file from being deleted, for example, between its selection and when your code takes action with it.
What happens if an invalid file is selected depends entirely on your code; ideally, you should check everything appropriate (file exists or not, is of the correct type, is not in a 'dangerous' location) and display proper error messages before your code does anything.
精彩评论