Click here to Skip to main content
15,896,471 members
Articles / Web Development / ASP.NET

An ASP.NET thumbnail solution

Rate me:
Please Sign up or sign in to vote.
4.61/5 (52 votes)
10 Dec 2002Ms-RL12 min read 599.8K   8.5K   266  
An article describing a set of ASP.NET tools for generation of thumbnails and thumbnail views.
<%@ Page Language="C#" Trace="false" %>
<%@ Register TagPrefix="PhilipSoft" TagName="ThumbList" Src="ThumbList.ascx" %>
<%@ import Namespace="System.Configuration" %>
<script runat="server">

    int width,height;
    protected void Page_Load(Object sender, EventArgs e)
    {
      String path,filter;
      if(!IsPostBack) {
       // create thumbnail-size combo data
       ArrayList arSizes = new ArrayList();
       for(int i=50; i<=500; i+=50)
         arSizes.Add(String.Format("{0}x{1}",i,i));
       cbThumbSize.DataSource=arSizes;
       cbThumbSize.DataBind();
       // create columns combo data
       ArrayList arCols = new ArrayList();
       for(int i=1; i<=10; i++)
        arCols.Add(i.ToString());
       cbColumns.DataSource=arCols;
       cbColumns.DataBind();
    
       // initial properties
       cbThumbSize.SelectedIndex=3; cbColumns.SelectedIndex=3;
       chkSaveThumbs.Checked = (ConfigurationSettings.AppSettings["DefaultSaveThumbnails"]=="true");
       txtPath.Text = Request.ApplicationPath.TrimEnd('/')+"/images/";
       txtFilter.Text = ConfigurationSettings.AppSettings["DefaultFilter"];
       if(txtFilter.Text=="") txtFilter.Text = "*.*";
       chkStretch.Checked = (ConfigurationSettings.AppSettings["DefaultAllowStretch"]=="true");
       int pagesize; try {
         pagesize = int.Parse(ConfigurationSettings.AppSettings["DefaultPageSize"]);
       } catch(ArgumentNullException ex) { pagesize=10; }
       txtPagesize.Text = pagesize.ToString();
       chkUseCOMobj.Checked = (ConfigurationSettings.AppSettings["EnableThumbnailCOMobject"]=="true");
      } // if not postback
      String sSize = cbThumbSize.SelectedItem.Text;
      int pos = sSize.IndexOf('x');
      width = int.Parse(sSize.Substring(0,pos));
      height = int.Parse(sSize.Substring(pos+1));
      // set properties of thumbnail control
      ThumbList1.VPath=txtPath.Text;
      ThumbList1.Filter=txtFilter.Text;
      ThumbList1.SaveThumbnails = chkSaveThumbs.Checked;
      ThumbList1.Width = width;
      ThumbList1.Height = height;
      ThumbList1.HeaderTitle =
       "<h3>Thumbnail images of directory " +  ThumbList1.VPath + "</h3>";
      ThumbList1.Columns = int.Parse(cbColumns.SelectedItem.Text);
      ThumbList1.ShowFilenames = chkShowFiles.Checked;
      ThumbList1.Sort = chkSort.Checked;
      ThumbList1.AllowPaging = chkPaging.Checked;
      ThumbList1.PageSize = int.Parse(txtPagesize.Text);
      //ThumbList1.HideNavBar = true; ThumbList1.CurPage=1; // test
      ThumbList1.AllowStretch = chkStretch.Checked;
      ThumbList1.UseCOMobj = chkUseCOMobj.Checked;
      ThumbList1.Bevel = chkBevel.Checked;
      ThumbList1.ItemBackColor = System.Drawing.Color.White;
      // new properties
      ThumbList1.ShowComments = chkShowComments.Checked;
      ThumbList1.AllowEdit = chkAllowEdit.Checked;
       //
    } //page_load
    
    void chkPaging_CheckedChanged(Object sender, EventArgs e) {
      txtPagesize.Enabled = chkPaging.Checked;
    }

</script>
<html>
<head>
    <title>PhilipSoft Thumbnail control test page</title>
</head>
<body style="FONT: 9pt verdana">
    <form runat="server">
        <p>
        </p>
        <h1>.NET ThumbList control test page 
        </h1>
        <p>
            <br />
            Path:<asp:TextBox id="txtPath" runat="server" Width="251px" BackColor="Linen"></asp:TextBox>
            &nbsp; Filter:<asp:TextBox id="txtFilter" runat="server" Width="93px" BackColor="Linen"></asp:TextBox>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            <br />
            <br />
            Select thumbnail size: 
            <asp:DropDownList id="cbThumbSize" runat="server" BackColor="Linen"></asp:DropDownList>
            &nbsp;&nbsp; Columns: 
            <asp:DropDownList id="cbColumns" runat="server" BackColor="Linen"></asp:DropDownList>
            &nbsp;&nbsp;&nbsp; 
        </p>
        <p>
            <asp:CheckBox id="chkSaveThumbs" runat="server" Text="Save thumbnails"></asp:CheckBox>
            &nbsp;&nbsp; 
            <asp:CheckBox id="chkShowFiles" runat="server" Text="Show filenames" AutoPostBack="True"></asp:CheckBox>
            &nbsp;&nbsp;<asp:CheckBox id="chkSort" runat="server" Text="Sort" AutoPostBack="True"></asp:CheckBox>
            &nbsp; 
            <asp:CheckBox id="chkPaging" runat="server" Text="Allow paging" AutoPostBack="True" Checked="True" OnCheckedChanged="chkPaging_CheckedChanged"></asp:CheckBox>
            &nbsp;&nbsp;&nbsp; Pagesize: 
            <asp:TextBox id="txtPagesize" runat="server" Width="37px" BackColor="Linen">3</asp:TextBox>
        </p>
        <p>
            <asp:CheckBox id="chkStretch" runat="server" Text="Stretch thumbnails" AutoPostBack="True"></asp:CheckBox>
            &nbsp; 
            <asp:CheckBox id="chkBevel" runat="server" Text="Beveled" AutoPostBack="True"></asp:CheckBox>
            &nbsp; 
            <asp:CheckBox id="chkUseCOMobj" runat="server" Text="Use COM object" AutoPostBack="True"></asp:CheckBox>
            &nbsp;
        <p>
            <asp:CheckBox id="chkShowComments" runat="server" Text="Show Comments" Checked="True" AutoPostBack="True"></asp:CheckBox>
            &nbsp; 
            <asp:CheckBox id="chkAllowEdit" runat="server" Text="Allow editing"  Checked="True" AutoPostBack="True"></asp:CheckBox>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            <asp:Button id="cmdShow" runat="server" Width="156px" Text="Regenerate thumbnails"></asp:Button>
        </p>
        <br />
        &nbsp;&nbsp;<PhilipSoft:ThumbList id="ThumbList1" runat="server"></PhilipSoft:ThumbList>
        <br />
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under Microsoft Reciprocal License


Written By
Web Developer Forthnet
Greece Greece
Software developer and Microsoft Trainer, Athens, Greece (MCT, MCSD.net, MCSE 2003, MCDBA 2000,MCTS, MCITP, MCIPD).

Comments and Discussions