I am getting a System.IO.FileNotFoundException
error when I run this code. Have I done something drastically wrong in the code or is there something small that I haven't thought of yet?
I have made sure everything has permission and the file is definitely present and the correct file type.
public Form1()
{
InitializeComponent();
DirectoryInfo ImgD = new DirectoryInfo("C:/Users/Dan/ImgDirectory/");
FileInfo[] rgFiles = ImgD.GetFiles("*.jpg");
foreach (FileInfo fi in rgFiles)
{
listBox1.Items.Add(Path.GetFileNameWithoutExtension(fi.Name));
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox1.Image = System.Drawing.Image.FromFile(
@"C:/Users/Dan/ImgDirectory/" + listBox1.SelectedItem.ToString());
}