Open File Dialog, One Filter for Multiple Excel Extensions?
Use a semicolon OpenFileDialog of = new OpenFileDialog(); of.Filter = “Excel Files|*.xls;*.xlsx;*.xlsm”;
Use a semicolon OpenFileDialog of = new OpenFileDialog(); of.Filter = “Excel Files|*.xls;*.xlsx;*.xlsm”;
What I generally do is create an interface for an application service that performs this function. In my examples I’ll assume you are using something like the MVVM Toolkit or similar thing (so I can get a base ViewModel and a RelayCommand). Here’s an example of an extremely simple interface for doing basic IO operations … Read more
Try: Filter = “BMP|*.bmp|GIF|*.gif|JPG|*.jpg;*.jpeg|PNG|*.png|TIFF|*.tif;*.tiff” Then do another round of copy/paste of all the extensions (joined together with ; as above) for “All graphics types”: Filter = “BMP|*.bmp|GIF|*.gif|JPG|*.jpg;*.jpeg|PNG|*.png|TIFF|*.tif;*.tiff|” + “All Graphics Types|*.bmp;*.jpg;*.jpeg;*.png;*.tif;*.tiff”
Something like that should be what you need private void button1_Click(object sender, RoutedEventArgs e) { // Create OpenFileDialog Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); // Set filter for file extension and default file extension dlg.DefaultExt = “.png”; dlg.Filter = “JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif”; // Display OpenFileDialog by calling ShowDialog method Nullable<bool> … Read more
From the docs, the filter syntax that you need is as follows: Office Files|*.doc;*.xls;*.ppt i.e. separate the multiple extensions with a semicolon — thus, Image Files|*.jpg;*.jpeg;*.png;….
I have a dialog that I wrote called an OpenFileOrFolder dialog that allows you to open either a folder or a file. If you set its AcceptFiles value to false, then it operates in only accept folder mode. You can download the source from GitHub here
Basically you need the FolderBrowserDialog class: Prompts the user to select a folder. This class cannot be inherited. Example: using(var fbd = new FolderBrowserDialog()) { DialogResult result = fbd.ShowDialog(); if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) { string[] files = Directory.GetFiles(fbd.SelectedPath); System.Windows.Forms.MessageBox.Show(“Files found: ” + files.Length.ToString(), “Message”); } } If you work in WPF you have … Read more