Fun Pet Trick #7: Creating a Thumbnail List in About 1 Minute
By Patrick A. LorenzThis Fun Pet Trick shows how to create a thumbnail list of all images placed in a given directory. All you need is the DynamicImage control, a DataList, and the System.IO namespace. Here you go:
<%@ page language="C#" %>
<%@ import namespace="System.IO" %>
<script runat="server">
void Page_Load(object sender, System.EventArgs e)
{
DirectoryInfo directory = new
DirectoryInfo(Path.GetDirectoryName(this.Request.PhysicalPath));
this.DL_Thumbnails.DataSource = directory.GetFiles("*.gif");
this.DL_Thumbnails.DataBind();
}
</script>
<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form runat="server">
<asp:datalist runat="server" id="DL_Thumbnails" repeatcolumns="2">
<itemtemplate>
<asp:dynamicimage runat="server"
imagefile='<%# Eval("Name") %>'
width="150px">
</asp:dynamicimage>
</itemtemplate>
</asp:datalist>
</form>
</body>
</html>
What the sample actually does is scale all GIFs in the pages directory to 150 pixels width and displays them in the browser.Have I already mentioned that I love the new DynamicImage control? Well, I do! ;-)