Limiting the files that can be selected using Open FIle Dialog box

I got this C# windows forms application where I load either a XML file or a CSV file for some task operations. I got a Browse button. When I click the Browse button, Open File Dialog box appears and I can navigate to a location on my drive and choose the file and then upload it using an Upload button. If I load a JPG or a ZIP file or any file whose format is anything except CSV or XML, my application crashes. Is there any way of limiting the Open File Dialog box to open only CSV or XMl files alone in C#?

Answers


use

openFileDialog.Filter = "CSV files (*.csv)|*.csv|XML files (*.xml)|*.xml";

this way only csv files or xml files are shown. but nevertheless users can also select other filetypes if they type in the complete name - so check the filename that was selected and correct your code accordingly.


Need Your Help

PHPMailer password-protected attachment

php mysql passwords phpmailer password-protection

I'm making PHP script, that import some data from mysql database and send it via email in attachment. But there is one issue - in future there is possibility, that data will be sensitive. So I need...

Change apk name with Gradle

android gradle apk android-gradle

I have an Android project which uses Gradle for build process. Now I want to add two extra build types staging and production, so my build.gradle contains:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.