1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| protected void displayFolder_Click(object sender, EventArgs e) {
if ((pathText.Text != null) && (pathText.Text != "")) {
DirectoryInfo fileListing = null;
try {
fileListing = new DirectoryInfo(pathText.Text);
} catch {
errorLabel.Text = ERROR_MESSAGE_PATH;
tableImage.Rows.Clear();
}
if (fileListing != null) {
Bitmap image;
try {
HtmlTableRow pRow = new HtmlTableRow();
HtmlTableCell phimage = new HtmlTableCell();
phimage.InnerText = "Image";
phimage.Style.Add("background-color", "#555555");
phimage.Style.Add("color", "#FFFFFF");
pRow.Cells.Add(phimage);
HtmlTableCell pnom = new HtmlTableCell();
pnom.InnerText = "Nom de l'image";
pnom.Style.Add("background-color", "#555555");
pnom.Style.Add("color", "#FFFFFF");
pRow.Cells.Add(pnom);
HtmlTableCell ptaille = new HtmlTableCell();
ptaille.InnerText = "Taille en octets";
ptaille.Style.Add("background-color", "#555555");
ptaille.Style.Add("color", "#FFFFFF");
pRow.Cells.Add(ptaille);
HtmlTableCell pdate = new HtmlTableCell();
pdate.InnerText = "Date de Modification";
pdate.Style.Add("background-color", "#555555");
pdate.Style.Add("color", "#FFFFFF");
pRow.Cells.Add(pdate);
tableImage.Rows.Add(pRow);
foreach (FileInfo file in fileListing.GetFiles()) {
image = null;
try {
image = (Bitmap)System.Drawing.Image.FromFile(file.FullName, true);
} catch (OutOfMemoryException) {
}
if (image != null) {
HtmlTableRow newRow = new HtmlTableRow();
HtmlTableCell himage = new HtmlTableCell();
//himage.InnerHtml = "<img src=\"D:/Image/mario/11786029.png\" alt=\"" + file.Name + "\"/>";
int w = image.Width;
int h = image.Height;
if ((w > MAX_WHIDTH_IMAGE) || (h > MAX_HEIGHT_IMAGE)) {
//en pourcent
float pw = MAX_WHIDTH_IMAGE / ((float)image.Width);
float ph = MAX_HEIGHT_IMAGE / ((float)image.Height);
float min = Math.Min(pw, ph);
//en pixel
w = (int)(image.Width * min);
h = (int)(image.Height * min);
}
himage.InnerHtml = "<img src=\"file:\\\\" + file.FullName + "\" width=\"" + w + "\" height=\"" + h + "\" style=\"margin:5px;\"/>";
newRow.Cells.Add(himage);
HtmlTableCell nom = new HtmlTableCell();
nom.InnerText = file.Name;
newRow.Cells.Add(nom);
HtmlTableCell taille = new HtmlTableCell();
taille.InnerText = file.Length.ToString();
newRow.Cells.Add(taille);
HtmlTableCell date = new HtmlTableCell();
date.InnerText = file.LastWriteTime.ToString("dd/MM/yyyy HH:mm");
newRow.Cells.Add(date);
tableImage.Rows.Add(newRow);
}
}
} catch {
}
}
}
} |