hello

I want to read images from a folder in my D:\ drive and place their names in dropdown box so that when i click on image name it opens in a picturebox. I am new at using c# can anyone help me in this regard

thanks

Here is how to enumerate files in a directory and write their full names to the console. With a bit of modification you can add the full name of the file as the value so when selecting it you have the path to it. Rendering it to a picture box should just be a matter of supplying the url to the picture box.

DirectoryInfo dirInfo = new DirectoryInfo(@"C:\MyDirectory");
IEnumerable<FileInfo> fileList = dirInfo.EnumerateFiles();

foreach (FileInfo fileInfo in fileList){
  Console.WriteLine(fileInfo.FullName);
}

Use the Coding which is given by abelLazm and including that to get the Images names from the folder use

string[] SubDirs = Directory.GetDirectories(Path)

Hope, it helps u.

Check out this code:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "Image Files(*.png; *.jpg; *.bmp)|*.png; *.jpg; *.bmp";
            // Allow the user to select multiple images.
            open.Multiselect = true;
            open.Title = "Image browser";

            if (open.ShowDialog() == DialogResult.OK)
            {
                foreach (String file in open.FileNames)
                {
                    string fullfileName = System.IO.Path.GetFullPath(file);
                    string showFileName = System.IO.Path.GetFileName(file);

                    comboBox1.Items.Add(new ComboBoxItems { FullPath = fullfileName, FileName = showFileName });
                }
                comboBox1.DisplayMember = "FileName";
                comboBox1.ValueMember = "FullPath";
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string filePath = (comboBox1.SelectedItem as ComboBoxItems).FullPath;
            if (filePath != String.Empty)
            {
                pictureBox1.Image = new Bitmap(filePath);
                this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
            }
        }
    }
    class ComboBoxItems
    {
        public string FullPath { get; set; }
        public string FileName { get; set; }
    }

Thank you all for your quick response hope you will also help me in future :)

This question has already been answered. Start a new discussion instead.