Hej, jag använder mig utan följande kod för att lista och skapa thumbnails av bilder. Bilderna visas nu i bokstavsordning men jag skulle vilja att de visades efter datum, men det senaste överst. Sortera bilder ur en mapp efter datum
<code>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<meta http-equiv="PRAGMA" content="NO-CACHE" />
</head>
<script language="c#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Modify these numbers for the thumbnail size you want
const int maxWidth = 200;
const int maxHeight = 200;
ArrayList pics = new ArrayList();
string html;
int imgHeight;
int imgWidth;
foreach(string s in Directory.GetFiles(Server.MapPath(""), "*.jpg"))
{
System.Drawing.Image currentImage = System.Drawing.Image.FromFile(s);
imgHeight = currentImage.Height;
imgWidth = currentImage.Width;
if ((imgWidth > maxWidth) || (imgHeight > maxHeight))
{
int deltaWidth = imgWidth - maxWidth;
int deltaHeight = imgHeight - maxHeight;
double scaleFactor;
if (deltaHeight > deltaWidth)
{
scaleFactor = Convert.ToDouble(maxHeight) / imgHeight;
}
else
{
scaleFactor = Convert.ToDouble(maxWidth) / imgWidth;
}
imgWidth = Convert.ToInt32(imgWidth * scaleFactor);
imgHeight = Convert.ToInt32(imgHeight* scaleFactor);
}
if ((imgHeight != currentImage.Height) || (imgWidth != currentImage.Width))
{
html = "" + "" + "";
}
else
{
html = "" + "" + "";
}
pics.Add(html);
}
dlPictures.DataSource = pics;
dlPictures.DataBind();
}
</script>
<!--Adjust these values as required! -->
<body bgcolor="#AAAAAA" link="#000000" vlink="#000000" alink="#000000">
<asp:DataList runat="server" id="dlPictures"
RepeatColumns="4"
GridLines = "Both"
ItemStyle-HorizontalAlign="Center"
cellpadding="20"
cellspacing="0"
BorderColor ="Black"
BorderStyle="Solid"
BorderWidth="1"
HorizontalAlign="Center"
VerticalAlign="Middle">
<ItemTemplate>
<%# Container.DataItem %>
</ItemTemplate>
</asp:DataList>
</body>
</html>
</code>