Click here to Skip to main content
Click here to Skip to main content

Photo album browsing control

By , 1 Dec 2004
 

Introduction

This control allows someone to include a photo album browser on their website with the minimum of fuss. It is implemented as a web control that can be sited within a parent ASP.NET page. It automatically generates a treeview of navigable albums, the album pages themselves and all the navigation elements. New albums can be uploaded by just uploading a directory containing the source images to a specific folder on the server.

To see a live running example go to http://www.codefresh.com/PhotoBrowser.aspx

Background

Previous to writing this web control I was using JAlbum to create static HTML pages for all the photos that I wanted to host on my website. Eventually the number of photos I was putting online was becoming unmanageable and I was finding it a chore to write the HMTL to link all of the albums together. I therefore decided to write an application that allowed me to simply upload the photos to the server and get ASP.NET to do the hard work of producing the pages. My first attempt worked but was a bit clunky due to me not knowing ASP.NET particularly well. What is presented here is my second version which I think is much improved. The control will render the album treeview, which is based on the file structure under a specified ‘photos’ directory. As the user navigates around the photos, the web control produces thumbnail pages for each album. This can be navigated through via the usual forward and back buttons. The user can examine photos in greater detail by clicking on each thumbnail, at which point they are also able to add comments.

Using the code

The code is comprised of three Visual Studio 2003 projects

  • The PhotoBrowser project is an ASP.NET web application that contains the control that renders the HTML.
  • The PhotoBrowserLibrary class project that encapsulates the photo directory file structure.
  • And the squishyTREE project which contains the treeview control that is used to display the album list. Note that this project is copy of the one released by squishyWARE, modified by adding a parent property to the TreeNode class.

In order to use the photo browser in your web application you'll need to perform the following steps:

  1. Import the PhotoBrowser.ascx file and the PhotoBrowserRes directory. PhotoBrowser.ascx is the web control itself and the PhotoBrowserRes directory contains the images it requires.
  2. Add a reference to the PhotoBrowserLibrary DLL and the squishyTREE DLL.
  3. Add the following line to you page, just before the closing </head> tag:.
    <script type="text/javascript" src="PhotoBrowserRes/overlib/overlib.js">
    <!-- overLIB (c) Erik Bosrup --></script>
  4. Add the following line just after the <body> tag.
    <div id="overDiv" style="position:absolute; visibility:hidden; 
    z-index:1000;"></div>
Then simply drag the web control on to your .aspx page, as shown below.

Points of Interest

The treeview is implemented using the excellent squishyTREE control from http://www.squishyweb.com. The comment popups were implemented using the excellent overLib. I used some code from here to help me sort out getting the date the photo was taken from the embedded EXIF data (apologies if this is the wrong link but I can’t honestly remember where it came from).

Popups by overLIB!

Known Issues

The application currently only detects changes in the photos contained within a directory when the number stored in the database and the number on the file system differs. This is for performance reasons. At some point in the future I would like to make this cleverer so that it can detect when an image has been 'touched' (e.g. its size changes). There is also no way to use a hyperlink to externally link to a single album (although you can use a link for individual photos). Lastly, I know there are a number of issues with the attached CSS. This CSS was *obtained* from JAlbum and I haven't had a chance to strip it down to the bare minimum.

I welcome any feedback or comments.

History

  • 1.3 (2 Dec 2004)
    • Implemented the comment popups using overLib.

  • 1.2 (29 Nov 2004)
    • Removed the Tooltip JavaScript includes from the source archive due to not being aware of the licensing restrictions.

  • 1.1 (26 Nov 2004)
    • Updated to handle ampersands in photo filenames and for the source archive to include the squishyTREE control project.

  • 1.0 (24 Nov 2004)
    • Initial release

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

n_1_c_k
Web Developer
United Kingdom United Kingdom
Member
I'm currently working in London working on a variety of technologies.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 2memberMd. Touhidul Alam Shuvo29 Jun '11 - 17:19 
it is not working in VS 2008
GeneralNice Articlemembertempsh10 Mar '11 - 6:54 
Thank you n_1_c_k, your article drawn me out of a nightmare of implementing photo album
by the way, I have a question:
Is there a possibility to view an image in a larger size? for example, when user clicks on it a larger size of the same image is shown
GeneralLong time user... applying a thin film of silvermemberdigger695 Nov '09 - 14:07 
Nick, I've used this for a long time on my personal website. Since I host my own webserver, this makes it infinitely easier for me to bulk upload photos for my family and friends to see - w/o them having to register a flickr, kodak.com, etc.
 
I'm in the process of porting the concept to a silverlight front end. The source will be up on codeplex soon: PhotoBrowserAg. Thanks for the helpful app and the inspiration.
 
Best,
Mark
Questionwhy i get two error when run this project??memberCampbell071918 May '09 - 6:36 
i get error like this:
PhotoBrowser\PhotoBrowser.ascx.cs(174,27): error CS0104: 'TreeNode' is an ambiguous reference between 'System.Web.UI.WebControls.TreeNode' and 'squishyWARE.WebComponents.squishyTREE.TreeNode'
GeneralPerformance Solution - Use the 'modified' file attribute to the thumbnail image file name.memberwashdi19 Jul '08 - 6:43 
Use the 'modified' file attribute to the thumbnail image file name.
 
Washdi

GeneralPhoto Albummemberyaip2 Oct '07 - 13:45 
Take a look at this:
 
http://www.justthinkart.com/

GeneralHELPmemberKKK7111 Jun '07 - 4:44 
Error 1 'TreeNode' is an ambiguous reference between 'System.Web.UI.WebControls.TreeNode' and 'squishyWARE.WebComponents.squishyTREE.TreeNode' C:\tmp\PhotoBrowser\PhotoBrowser.ascx.cs 174
 
Error 2 'TreeNode' is an ambiguous reference between 'System.Web.UI.WebControls.TreeNode' and 'squishyWARE.WebComponents.squishyTREE.TreeNode' C:\tmp\PhotoBrowser\PhotoBrowser.ascx.cs 191
 
Can you help me?
GeneralProblems in IEmembermelonhed33 Feb '07 - 14:19 
This works for me in Firefox but in IE I get an error
 
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
 
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
 
Source Error:
 

Line 252: // unique ID
Line 253: Hashtable directoryLookup = (Hashtable) Context.Session["DirectoryLookup"];
Line 254: PhotoDirectory dir = (PhotoDirectory) directoryLookup[Int32.Parse(node.Key)];
Line 255:
Line 256: GeneratePhotosTable(dir, 1);

 
Source File: c:\inetpub\wwwroot\PhotoBrowser\PhotoBrowser.ascx.cs Line: 254
 
Stack Trace:
 

[NullReferenceException: Object reference not set to an instance of an object.]
Codefresh.PhotosBrowser.PhotoBrowser.tvwMain_SelectedNodeChanged(Object sender, EventArgs e) in c:\inetpub\wwwroot\PhotoBrowser\PhotoBrowser.ascx.cs:254
squishyWARE.WebComponents.squishyTREE.TreeView.RaisePostBackEvent(String eventArgument) in C:\Inetpub\wwwroot\PhotoBrowser\squishyTREE\TreeView.cs:455
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +174
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
 


 
Chris
QuestionAdding referencesmemberbschune9 Jan '07 - 5:42 
I'm not familiar with adding references. In Visual STudio, i see where to add the references, but where do i get the squishyTree & photovrowser dlls to refer to? i don't see them in the code download.
GeneralCould not use ''; file already in use. Error [modified]membermetalguy907 Dec '06 - 3:56 
Here is the error message:

[OleDbException (0x80004005): Could not use ''; file already in use.]
System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr) +20
System.Data.OleDb.OleDbConnection.InitializeProvider() +57
System.Data.OleDb.OleDbConnection.Open() +203
Codefresh.PhotoBrowserLibrary.DirectoryBrowser.OpenDatabaseConnection(String photosPhysicalPath) +87
Codefresh.PhotoBrowserLibrary.DirectoryBrowser..ctor(String photosPhysicalPath) +28
Codefresh.PhotosBrowser.PhotoBrowser.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\PhotoBrowser.ascx.cs:89
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Page.ProcessRequestMain() +750

 
this happens when you view the page once, then close the browser and go to the page again.
 
how do i go about resolving this? is anyone else have this issue?
also to note, the photobrowser application is pointing to the C:\ drive. However, I have moved the website to my G:\ drive. Is this causing the problem?
 

-- modified at 10:34 Thursday 7th December, 2006
GeneralRe: Could not use ''; file already in use. Errormembern_1_c_k7 Dec '06 - 4:01 
You've probably got the database open in Access whilst running the code.
 
Nick
GeneralRe: Could not use ''; file already in use. Error [modified]membermetalguy907 Dec '06 - 4:55 
that's the thing. i am not opening it with Access.
it seems that when one person opens the DB, another attempt to open the db fails and retuns the error message "file already in use"
GeneralRe: Could not use ''; file already in use. Errormembermetalguy907 Dec '06 - 7:25 
i did some research on this and found out that it was a permissions issue.
thanks for the response and thanks for the wonderful asp control. Smile | :)
QuestionNo Display on my ScreenmemberMichram3 Oct '06 - 5:17 
When I tried to run the project, there's no display on my screen and I couldn't add to the database. What should I do to make it appear in my screen? Thanks!
GeneralDatabase permission Problemmemberejazan2 May '06 - 7:17 
When ever I try to access the Photo Album, I got the following problem:
 
Error Message:
 
Server Error in '/PhotoBrowser' Application.
Could not use ''; file already in use ( By '' means PhotoServer.mdb file).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
 
Exception Details: System.Data.OleDb.OleDbException: Could not use ''; file already in use.
 
Source Error:
 
Line 87: string mappedPhotosPath = request.MapPath(photosPath) + "photos";
Line 88:
Line 89: dirBrowser = new DirectoryBrowser(mappedPhotosPath);
Line 90:
Line 91: }
 

Source File: c:\inetpub\wwwroot\photobrowser\photobrowser.ascx.cs Line: 89
 
Stack Trace:
 
[OleDbException (0x80004005): Could not use ''; file already in use.]
System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr)
System.Data.OleDb.OleDbConnection.InitializeProvider()
System.Data.OleDb.OleDbConnection.Open()
Codefresh.PhotoBrowserLibrary.DirectoryBrowser.OpenDatabaseConnection(String photosPhysicalPath)
Codefresh.PhotoBrowserLibrary.DirectoryBrowser..ctor(String photosPhysicalPath)
Codefresh.PhotosBrowser.PhotoBrowser.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\photobrowser\photobrowser.ascx.cs:89
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
 
Error Message End:
 
I think it is due to fact that Connection is open only once and not closed and when other user try to access it, Photoalbum throws error that data is already in use.
 
Please help me out of this problem
 
Thanks.
Ejaz
 

-- modified at 20:27 Tuesday 2nd May, 2006
GeneralPhotobrowser doesn't startmemberfrans.douven24 Mar '06 - 2:25 
I get a error: Operation must be performed on a query which can be updated.
Exception Details: System.Data.OleDb.OleDbException: Source Error:
Line 81: cmd.Parameters.Add(CreateStringParam("VirtualPath", photoDirectory.VirtualPath));
Line 82:
Line 83: cmd.ExecuteNonQuery();
Source File: F:\Download\fotoalbum\PhotoBrowser\PhotoBrowserLibrary\PhotoDirectoryDB.cs Line: 83
What does it mean?
(PhotosServer.mdb is empty???)
 


 
F. Douven
GeneralRe: Photobrowser doesn't startmembern_1_c_k24 Mar '06 - 2:32 
This usually means the PhotoServer.mdb file is read only. Clear this flag and it should work fine.
 
Edit: You might like to see this post as well
 
Nick
 
-- modified at 8:33 Friday 24th March, 2006
GeneralRe: Photobrowser doesn't startmemberfrans.douven24 Mar '06 - 3:21 
Sorry, but the mdb file is read/write!
AnswerRe: Problem in the castingmembern_1_c_k22 Mar '06 - 7:58 
Sorry I haven't a clue on this one. What is the object type that like 148 is returning?
QuestionHow to use this in ASP.NET 2.0memberyaip23 Jan '06 - 10:12 
I have VS 2005. Could you please give a step-by-step as to how to use this with that?
AnswerRe: How to use this in ASP.NET 2.0memberepf197525 Jan '06 - 7:26 
I too am interested in a VS 2005 release. Or at least a version that can be converted. Any idea when this might happen? Confused | :confused:
 
epf
 
-- modified at 13:26 Wednesday 25th January, 2006
AnswerRe: How to use this in ASP.NET 2.0membern_1_c_k30 Jan '06 - 9:13 
Sorry but I don't have the time to convert it. I have actually done the conversion for my private site and it wasn't that difficult.
 
Nick
GeneralRe: How to use this in ASP.NET 2.0memberepf19752 Feb '06 - 16:33 
Do you think you could share your converted code with a very dumb novice programmer? Sniff | :^)
GeneralRe: How to use this in ASP.NET 2.0membern_1_c_k23 Feb '06 - 9:33 
Sorry I don't have it in a fit state at the moment. I will try to in the futute but no promises.
 
Nick
GeneralVery Good.memberBrian.Xue3 Jan '06 - 15:00 
Big Grin | :-D I am a Chinese, I'm so glad to see your source.
Thank you!

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 2 Dec 2004
Article Copyright 2004 by n_1_c_k
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid