Daniel Lip
Daniel Lip

Reputation: 11317

How to use FileDialog to select either specific files names extensions or all the files?

private void button1_Click(object sender, EventArgs e)
        {
            VistaOpenFileDialog dialog = new VistaOpenFileDialog();
            {
                dialog.Filter = "Images (*.jpg, *.bmp, *.gif)|*.jpg;*.bmp;*.gif";
                dialog.Filter = "All Files (*.*)|*.*";
            };

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = dialog.FileName;

                Bitmap bmp = new Bitmap(Image.FromFile(dialog.FileName),
                    pictureBox2.Width, pictureBox2.Height);
                pictureBox2.Image = bmp;
            }
        }

I'm using ookii package with VistaOpenFileDialog but i guess the idea should be the same as with the regular OpenFileDialog class.

now when i click it's showing the All Files option when i expand it i can't see the first option Images.

i want that it will show first the Images option and then to be able to switch the All Files.

Upvotes: 1

Views: 276

Answers (1)

IamK
IamK

Reputation: 2974

You are overwriting your filter property. To add multiple file type filters:

dialog.Filter = "Images (*.jpg, *.bmp, *.gif)|*.jpg;*.bmp;*.gif|All Files (*.*)|*.*";

Upvotes: 2

Related Questions