OpenFileDialog.Multiselect Property
Gets or sets a value indicating whether the dialog box allows multiple files to be selected.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Property Value
Type: System.Booleantrue if the dialog box allows multiple files to be selected together or concurrently; otherwise, false. The default value is false.
The following code example allows the user to select a number of images and display them in PictureBox controls on a Form. It demonstrates initializing an OpenFileDialog, setting the Title and Filter properties, and allowing the user to select multiple files by setting the Multiselect property to true. This code example assumes that your form already has an OpenFileDialog control named openFileDialog1, a Button named SelectFileButton, and a FlowLayoutPanel named flowLayoutPanel1.
private void Form1_Load(object sender, EventArgs e) { InitializeOpenFileDialog(); } private void InitializeOpenFileDialog() { // Set the file dialog to filter for graphics files. this.openFileDialog1.Filter = "Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" + "All files (*.*)|*.*"; // Allow the user to select multiple images. this.openFileDialog1.Multiselect = true; this.openFileDialog1.Title = "My Image Browser"; } private void selectFilesButton_Click(object sender, EventArgs e) { DialogResult dr = this.openFileDialog1.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { // Read the files foreach (String file in openFileDialog1.FileNames) { // Create a PictureBox. try { PictureBox pb = new PictureBox(); Image loadedImage = Image.FromFile(file); pb.Height = loadedImage.Height; pb.Width = loadedImage.Width; pb.Image = loadedImage; flowLayoutPanel1.Controls.Add(pb); } catch (SecurityException ex) { // The user lacks appropriate permissions to read files, discover paths, etc. MessageBox.Show("Security error. Please contact your administrator for details.\n\n" + "Error message: " + ex.Message + "\n\n" + "Details (send to Support):\n\n" + ex.StackTrace ); } catch (Exception ex) { // Could not load the image - probably related to Windows file system permissions. MessageBox.Show("Cannot display the image: " + file.Substring(file.LastIndexOf('\\')) + ". You may not have permission to read the file, or " + "it may be corrupt.\n\nReported error: " + ex.Message); } } }
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.