I need to search for images in all subdirectories and display them in picturebox
, but the code I currently have is only allowed to search in a single folder and not filtered by file types such as *jpg
, *png
, etc ...
Below is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace _myfotospf
{
public partial class FormFotos1 : Form
{
public FormFotos1()
{
InitializeComponent();
}
private void FormFotos_Load(object sender, EventArgs e)
{
string[] files = Directory.GetFiles(@"C:\Users\...\Imagens");
DataTable table = new DataTable();
table.Columns.Add("Nome do ficheiro (duplo clique para ver a miniatura)");
for (int i = 0; i < files.Length; i++)
{
FileInfo file = new FileInfo(files[i]);
table.Rows.Add(file.Name);
}
dataGridView1.DataSource = table;
}
private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
FormFotos2 myForm = new FormFotos2();
string imageName = dataGridView1.CurrentRow.Cells[0].Value.ToString();
Image img;
img = Image.FromFile(@"C:\Users\...\Imagens\" + imageName);
myForm.pictureBox1.Image = img;
myForm.ShowDialog();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}