It's Microsoft's World, and I'm just living in it
View Clarence Klopfstein's profile on LinkedIn

Clarence Klopfstein's Facebook profile

This site is under construction...


New Comments

Referring Sites


  • This is MY blog. The views represented here are not in relation to anybody else. Please read my full disclaimer for a more complete disclaimer.

Creating a photo gallery

November 12, 2007 21:35 by ckincincy

I needed a simple way to create a photo gallery for my churches website, so I started off by doing a search for something that already exist.  I found gphotonet, and thought it was a good thing to start with.

However there were some things I wasn't happy with.  First it would require a lot of heavy lifting by the web server to create the thumbnails on the fly.  Second it would have me uploading some pretty large images (as 10MP cameras put some serious file sizes out).  So first I took some of the logic in this code and created an application that would create the images for me as static files.  Then I edited the page to load from my custom directories and from the database that would have some basic information about the galleries.  Now all of that I would hope you could figure out on your own, but if you need help feel free to contact me.

What I liked about this process was how easy it was to load the image into an ASP.NET component :<asp:datalist/>  This is just a really cool feature.  

I started off by creating an array list and looping through the images in a directory and filling the array list, then I used databound to put that array in the datalist, IT takes care of the rest creating the galleries you see on my churches website.  Here is the basic HTML and code behind I used:

 <asp:DataList runat="server" id="dlPictures" RepeatDirection="Horizontal"  
         GridLines = "None"
         BorderColor ="Black"
         VerticalAlign="Middle" >    
        <%# Container.DataItem %>

Code to fill DataList:
         string picUrl = Request.QueryString["picDir"];
            ArrayList pics = new ArrayList();
            if (picUrl != null && picUrl != string.Empty)
                string html;
                foreach (string s in Directory.GetFiles(Server.MapPath(picUrl + "\\250"), "*.jpg"))
                    html = "<a href=\"viewimage.aspx?path=" + picUrl + "&img=" +
                        Path.GetFileName(s) + "\">" + "<img border=\"0\" src=\"" +
                        picUrl + "\\250\\" + Path.GetFileName(s) + "\" \">" + "</a>";

                string DB_CON = @"MY DB CONNETION";
                string SQL = "MY SQL STATEMENT";

                OleDbConnection con = new OleDbConnection(DB_CON);
                OleDbCommand cmd = new OleDbCommand(SQL, con);

                OleDbDataReader rdr = cmd.ExecuteReader();
                if (rdr.HasRows)
                    while (rdr.Read())
                        string html;
                        string AlbumPath = rdr["path"].ToString();
                        string AlbumName = rdr["album"].ToString();
                        string AlbumCount = rdr["count"].ToString();
                        html = "<a href=\"default.aspx?picDir=" + AlbumPath +
                            "\">" + "<img border=\"0\" src=\"" +
                            AlbumPath + "\\gallery.jpg" + "\" />" + "</a>" +
                            "<br/>" + AlbumName + " - " + AlbumCount + " images";

            dlPictures.DataSource = pics;


Hope this helps you. 

Categories: ASP.NET
Actions: E-mail | Permalink | Comments (1) | Comment RSS


January 14. 2008 21:46

I've got some serious studying/coding to do.

Jennifer |

Comments are closed