OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Image Files (*.png;*.jpg;*.gif)|*.png;*.jpg;*.gif"; if (openFileDialog.ShowDialog() == DialogResult.OK) { pictureBox1.Image = new Bitmap(openFileDialog.FileName); }
OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Folders Only|*.none"; openFileDialog.CheckFileExists = false; openFileDialog.CheckPathExists = true; openFileDialog.FileName = "Select Folder..."; if (openFileDialog.ShowDialog() == DialogResult.OK) { textBox1.Text = Path.GetDirectoryName(openFileDialog.FileName); }Both examples use the System.Windows.Forms namespace and the OpenFileDialog class.