Fun Pet Trick 7: Creating a Thumbnail List in About 1 Minute


Fun Pet Trick #7: Creating a Thumbnail List in About 1 Minute

By Patrick A. Lorenz

This 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"  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! ;-)




ASP. NET 2.0 Revealed
ASP.NET 2.0 Revealed
ISBN: 1590593375
EAN: 2147483647
Year: 2005
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net