A simple ASP.NET photo album

In June, Dmitry posted a very simple photo album on his blog. I immediately liked it because it's both easy to set-up (just drop the ashx file into your web site's photo directory) and to manage (no need to upload images one by one using a clumsy web upload field, just upload new photos using ftp or the file system). It's also nice to browse. Sure, there are no fancy ratings or comments features, you can't add titles or descriptions, but frankly, I didn't need all these features.

Still, I wanted to change a few things so I went ahead and added the following to Dmitry's handler:

  • XHTML output
  • CSS styling
  • EXIF meta-data reading and displaying
  • Sorting by date shot
  • Stacked photos folder icons (uses default.jpg if it exists)
  • Folder names respect casing and special characters
  • In-handler pseudo-config (just modify the handler's configuration block with any text editor)
  • Thumbnail caching on disk or in memory
The thumbnail caching on disk is an essential improvement because if you have a large number of heavy pictures, memory won't be the right place to cache. If the handler is configured to save on disk (which is the default), the thumbnails are stored in the application's temporary folder, the very same place where pages are compiled. This means that you don't need to set writing permissions, but it also means that you need to run in high or full trust. If you can't do that, you should configure the handler to cache in memory or not at all.

Photo album folders
Viewing folders

Photo Album List View
Viewing thumbnails

Photo Album Details View
Viewing details

The handler is under a shared source licence, which means that you can do pretty much what you want with it. It uses the Metadata public domain library by Drew Noakes and adapted for .NET by Renaud Ferret to extract the EXIF information from the jpeg files. This library can be downloaded from http://renaud91.free.fr/MetaDataExtractor. Please use the dll from the workspace below, though, as I've made a small correction. I've also sent the correction to Renaud, but he may not publish a new version immediately...

Download the code for the handler here:

Special thanks should go to Dmitry Robsman and David Ebbo.

UPDATE: the handler is now hosted on Codeplex.


  • Hi

    Tried this and it's very nice indeed - thanks for your efforts. Is the version on gotdotnet the same as your demo pics? When I tried it the output doesn't look as neat and the pictures all appear in a single column.

  • Wow looks very nice... I will definately be testing this out for a image gallery part of a personal website :)

  • You're absolutely right, the CSS that's included in release 1.1 is an old version. You can now download the right CSS file from release 1.1.1 or from source control.

    Please tell me how that works for you.

  • Stupid question but how do I get this to work.

    Just putting it in the right directory didn't do much for me.

  • Mischa, what happens when you browse to the handler?

  • Can u tell me how implement this.
    I mean that how to create simple album application.

  • Rio, why don't you start by downloading the source code and studying it?

  • possible to support bmp, gif and png also ?

  • Infinity: it's shared source, so feel free to implement that, but I won't in the near future, jpeg being the dominant format for photos. Sorry.

  • This is a great software.

    But I can only run it on Windows 2000 Server. I've tried two different Windows 2003 servers. With no luck.

    Does anybody know how to get this running on Windows 2003 Server?

  • Tom, I'm running it at home on Windows 2003 Server without a problem. What exactly is the problem you're seeing? Are you sure you have ASP.NET 2.0 installed? Is ASP.NET activated in IIS?

  • I dropped the files in an image directory, and I'm getting the following error: "The type or namespace name 'com' could not be found" on the com.drew.metadata namespaces.

  • For the moment, you also need to copy the dll to the bin folder. I'm working on a new version that removes that requirement.

  • Thanks for the quick response. To clarify, I moved MetaDataExtractor.dll to my site's root bin directory, and that solved the problem. Looks like a great tool.

  • Looks good, but the link to download isn't working. This is a long shot, but would you want to code in a user management system so only certain users could access certain folders?

  • Jared: I just tried the link and it's working for me. Maybe the site was down when you tried. I don't think there's a need for a specific user management system: the built-in membership system of ASP.NET should work fine with it.

  • Looks like the link was down when I last tried, thanks. I've been playing around with it a bit (mainly to get it to play with a different source directory, a networked drive) and noticed it has trouble with hidden/corrupted .jpg files (these are being created by Mac users somehow). Also, is there any way to add in non-jpeg files (gif, tif, png, etc.)? It seems it is limited to what the MetaDataExtractor can read.

  • Jared: I think you'd have to fix those jpgs before you use them with the handler. Both corrupt jpg and non-jpg file handling are features I don't plan on adding for the moment as I have little time and more important features to implement but feel free to modify the code any way you want and implement those.

  • Bertrand: i downloaded the albumhandler.zip (2.0 and 2.1) and extract the files into the image folder... when i run it, i got the following message:
    Parser Error Message: Type 'AlbumHandler' does not inherit from 'System.Web.UI.UserControl'.

    Source Error:
    Line 2:

    Do you have any idea what causes the problem?

  • You probably don't have ASP.NET 2.0 installed, or it's not active on that application.

  • Hey it's really great!!

    Is it possible to scan only a certain folder? Because right now it scans everything in my website ehhe

  • Mike: just put the handler in the folder you want to scan.

  • I am not able to use this code please help

  • Neeraj: you're going to have to give more details. First check that the web site you're trying to use it on has ASP.NET 2.0.

  • I can get the album to work great if I put it in the root of my site, but if I put it in one directory then it loads all the links, but no thumbnails....
    Any ideas?

    Thanks in advance!

  • Daniel, please file a bug on GotDotNet.

  • Daniel, I had the same trouble getting the album to work on a directory other than root as well, but I was able to figure out what was causing the problem. Though it has been a few weeks I believe you can solve it by specifying the HandlerUrl on the control.
    I am pretty sure that is what I found. I don't know that it is really a bug, but it should be noted in the instructions at least. The best structure I've found is to have a Subfolder as the root of your photoalbum. Put the ashx & the display page (aspx) in this folder, and create subfolders under that for each of your "albums".

  • Hey, this is a great control! I have a question though: I have a subdirectory 'photos', it contains the ashx and aspx files as well as the directories containing the photos I'd like to display on my site. On my localhost everything works perfectly, but after I uploaded everything to my webspace (after compiling of course) I can see only the links, no thumbnails or pictures (only those little red crosses). When I try to visit a permanent link to one of the albums I get a Server Error ("invalid path - not in the handler scope"). Any ideas on how to fix this? Thanks in advance!

  • Found the solution: the disk caching was the problem (I didn't have writing rights).

  • Calios: thanks for the suggestion, that's a really good point.

  • Found a little bug/annoyance - im posting it here since gotdotnet will phase out in a few days(19th of June 2k7).

    in CreateFolderImage you didnt fill in the BackGround - thus using any other background than black will look wierd :-O

    I added this to fix it:
    g.FillRectangle(new SolidBrush(BackGround), 0, 0, size, size);
    Right after the stacked Graphcis has been declared (was line 477 of the .ashx file for me - v 2.1 of the handler) :-)

  • Calios: thanks for the fix.

  • How about using this in Windows Home Server? Possible? How To? etc. Pretty Please? LOL


  • Judge: I've thought the exact same thing ever since I learned about Home Server. Unfortunately, I don't own one so I can't try it. However, from what I know I don't see what could prevent it from working. If anyone wants to try, I'd love to know how it goes...

  • Thanks Mike! This rocks!

  • This thing is outstanding. I love it. Now, having said that, I am having one small issue. I have a folder called Pictures where the web files reside. I have dirs 2002, 2003, 2004, and in those dirs 01, 02, 03. I can get into the year folder to see my months folder, but when I click on the link for the month folder nothing happens. What is the level of folders this can handle. Root + 1? Root + inf?

  • There shouldn't be a limit on the folder depth. Can you package a repro into a small zip file and send it to me at bleroy at microsoft dot com?

  • Bertrand,

    Kudos to you and all who contributed to this fine tool! Very easy to use and gives a great aesthetic look for a simple Photo Album.

    I do have a one question. I cant seem to get the stacked photos folder icon to work. I was hoping you could clarify "Stacked photos folder icons (uses default.jpg if it exists)".

  • Russ: how exactly does it not work? What I meant was that if you have a photo named default.jpg, the handler will use it as the top of the stack. Other photos will be randomly selected. If you don't have a default.jpg, it takes a random photo for the top of the stack. Does that help?

  • Russ: can you look for the UpFolderStackHeight setting in the handler and check that it's not set to 1?

  • UpFolderStackHeight = 3

  • Russ: then I have no idea, sorry. Never seen that happen.

  • Your photohandler works great in Internet Explorer.

    In Firefox, however, it shows the pictures (and directories) all in one column.

    Any idea how to fix this?



  • Bas: did you make any changes to the style sheet? I just checked and it displays fine in Firefox, Opera, Safari and IE.

  • Sona: not sure I'm following you, it seems to work fine on your site.

  • John: you forgot to drop the meta data extractor dll into the applicaiton's bin folder.

  • Ok first and foremost thank you for this awesome app!

    Now I've been trying to get this to work but to no avail. The issue I'm having is that it is scanning all my folders. I only need it to scan one specific folder and all subfolders under it. When I move the .ashx file and page to the folder that I want to show (meaning the main folder or first folder that should display) all I get are X's for all the images. Any ideas?

    Also, for those interested in changing the background color and aren't necessarily using a "named" color they can substitute the

    Color BackGround = Color.Black


    Color BackGround = ColorTranslator.FromHtml("#XXXXXX")

    Where the X's stand for the Hex code of the color.

    Any help for my issue described above would be great!!!

  • Axeman: you can try to see what the response was using Firebug or Fiddler for those images. I'd guess a trust level mismatch with your configuration. We can also continue this conversation offline (bleroy at microsoft dot com)

  • Great app!!!

    Is there a way to pass a different stylesheet to the handler, or have it use a different background. I have the app within a container on my home page and I would like to have it use a differnet background. It keeps using the background image of the main page and I can't figure out how to change it.


  • Ok I got everything to run fine on my local machine. When I publish to my site hosted by Godaddy.com I get a problem with the following code. Apparantly they are not giving me rights to the temporary asp.net folder this is using. Thanks in advance for your assistance.

    Static IMagehelper()

    _imageCacheDir = Path.Combine(HttpRuntime.CodegenDir, "Album");

    This is the error:
    Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

  • Beau: the stylesheet is inside the handler. It's very easy to change.

    Manoj: the license is MS-PL. See http://www.codeplex.com/PhotoHandler/Project/License.aspx

    John: there's a setting in the handler for the cache location. Disk only works if you have a high enough trust level. Memory and none works everywhere.

  • ok I found it and changed it to memory and all is well.

    Thank you

  • Robert: that's weird. Are you sure you included the same version of the dll that came with the release file? Just unzipping the release in a web app should works out of the box. Does it or did you do something different from that?

  • D'Oh i was being an idiot...

    I went to the link, clicked on the 'Source' tab and downloaded that. it only came with a samples folder etc and was wondering was was going on.

    I must be needing sleep!

    Thanks for the help Betrand

  • Just a quick question. I have 70 pictures in the share folder but only 22 show up on the web page. Am I missing something? I am using Windows Home Server RC1. My page is the above URL. I also posed this question on Andrew Grant's site.

    I like how easy it is to use.

  • Are all 70 photos .jpg files?

  • Actually 18 are jpeg and the balance is bitmap. Is that where I have gone wrong? The bitmaps are 1,800 - 2000 KB and the jpegs are 130 - 200 kb.

  • Phil: yes, the handler only takes jpg files.

  • Thanks, I converted all to Jpeg and they all show up now

  • A little more explaintion of the fix for black background on thumbnails please tried

    Found a little bug/annoyance - im posting it here since gotdotnet will phase out in a few days(19th of June 2k7). in CreateFolderImage you didnt fill in the BackGround - thus using any other background than black will look wierd :-O I added this to fix it: g.FillRectangle(new SolidBrush(BackGround), 0, 0, size, size); Right after the stacked Graphcis has been declared (was line 477 of the .ashx file for me - v 2.1 of the handler) :-)

    but did not change anything

  • Hi, I have the same problems with
    "using com.drew.metadata.exif" error.

    I've downloaded latest album files (AlbumHandler2_1), extracted to wwwroot.

    May I have to do anything else in IIS? (winxp)


  • Danilm: I'll give you the same answer I gave to other users who had the same problem and which you can read above... You probably forgot to copy the dll into the bin directory.

  • I'm sorry but I have copied the dll into the bin directory and it doesn't work

    is the right version:

    I've downloaded AlbumHandler2_1 that contains all the files and folders


  • Is the bin directory directly below the IIS application folder?

  • Awesome App Bertrand! I love how easy it is to use just the .ashx page! Now of course I have a question...

    My file structure is such:

    I had to change the CacheLocation to CacheLocation.Memory because of my host.

    When I run just the album.ashx it works perfectly, all the images display, only the 2007 and sub-directories show and navigation works fine.

    When I try and run the default.aspx (which I modified the original to have the src="album.ashx" instead of src="~/album.ashx") I see all directories from the root (minus hidden/protected ones) and only the red X image, no images anywhere, even in the 2007 and subs, but if I click "Details" it does show the EXIF details of the photo. The navigation still works fine, and when I get to the point where the tool tip would normally read "Click to view picture at full resolution", if I click that it opens a new browser and shows the photo as expected.

    Two Questions:
    1. Any idea why it doesn't show any of the photos when being called from the Default.aspx but works fine in the album.ashx?
    2. How do I make it so it only scans sub-directories from it's location when being called from the default.aspx file?

    Thanks for the awesome utility!

  • Trinity: I think that may be a bug. Please file it on the CodePlex site.
    The control will always limit what photos it displays to the directory where the handler is (not the page) and subdirectories.

  • Cab: what's the error?

  • Hi,

    I am trying to costumize the application, although I am not being able to change the backgroudn color for the upfolder and thunbnailfolder icons... I want my background to be white and for those its in black... any one can help?

  • Pedro: there are config entries in the handler as wel as forum posts and bugs on the CodePlex site that should get you started.

  • Is there a way to have handler pull images from a certain directory?
    Example file structure:
    ---->Folder 1
    ---->Folder 2
    ---->Folder 3

  • Mike: why don't you put the handler in the images folder?

  • Bertrand-

    You should not have blown M Anderson off like that. He/She is reporting a different issue (October 4, 2007 7:26 PM.)

    1. Calios' June 8, 2007 fix for the background of the stacked Folder Immages works just fine. So it is no longer a "known issue" but rather a fixed issue.

    2. What M Anderson is reporting is a peculiarity that I do not fully understand but can discribe. If you make the change Calios describes, the thumbnails don't change until you change the folder names. The thumbnails are stored in the application's temporary folder, background and all. They do not change just becuase you say you wnat them to look different. You have to do something to cause them to re-write.

  • ttomm: right, and this is a known issue too. If you want to regenerate the thumbnails, for the moment, you need to physically delete them or somehow restart the appdomain (touching web.config should do the trick). The original issue is not fixed in the sense that the fix is not yet in the current release, so it's a "known fix" rather than a "fixed".

  • Awesome little app, however I have some issues with it, when I add the required files to the directory, it shows everything as it is supposed to, however when I click on an image, to see if in the center of the screen, it doesnt show at all, it only shows the 'Details', 'Previous Image' and 'Return to Folder View'.

    I like this app very much, but I would LOVE for it to show the image in the center of the screen.

    I'm running this on WHS (Home Server) and the client OS is Vista, with IE7.

  • Jeff, please contact me through the contact form, and I'll look into it.

  • Hi Bertrand,

    I want to change background color of thumbnail. I changed the following code:

    private static readonly Color BackGround = Color.White;

    However, the color remains blank.

    Please help. Thanks.

  • Cathy: that's this issue:
    The bug is not fixed in the current release but the discussion on it contains a fix.

  • hello, seems to be a nice album, but it's not working on my hoster. sohosted.com

    I also have this problem:
    The issue I'm having is that it is scanning all my folders. I only need it to scan one specific folder and all subfolders under it. When I move the .ashx file and page to the folder that I want to show (meaning the main folder or first folder that should display) all I get are X's for all the images. Any ideas?

    sohosted.com is running on medium trust, changin the location of the cache to none or memory doesn't fix the problem....

    somebody knows what to do?


  • @Lou: it seems like you're using the user control version. If that's the case, you can try to set the HandlerUrl property to point at the ashx file, and also the Path property on non-postback requests.

  • Sridhar: I have no idea. The image isn't even in the dom. Drop me e-mail at bleroy at microsoft com and we'll try to debug into it.

  • @Michael: I have no idea. You should check that with your hoster. Let me know what you find.

  • I was wrong...Memory Caching sorted it out.
    But I get some links and red croses though in some of
    the pictures though...Is this a bug or Is there a work around with this.

    Thanks very much

  • @Michael: are the broken images consistently the same images? Are they jpeg images? Is there a public url where I could have a look?

  • Hi Bertrand,

    My images are in jpeg format.
    (thumbnails) red crosses and link are coming out inconsistently in these series...

    thummnail ok thummnail ok thumbnail ok red cross red cross red cross link link link thumbnail ok...

    I say inconsistenly, I mean sometimes when you view the gallery red crosses and links come out the other time they are fine.

    url: www.aikidoclub.net

    Thanks very much

  • @Michael: we should take that offline. Please write me e-mail at bleroy at microsoft. There is a server error on these images but I'm unable to diagnose it because you have cutom errors on (which you should, this is absolutely the right setting). We should be able to sort this out via e-mail. Thanks.

  • This is working fine on my local machine
    but on the server it just shows white bg , missing images and links , I have set my server to allow the application write permission. Any thoughts

  • Check that you configured the directory where the handler is as a web application.

  • Need Help, I get the album to work when I debug but when I publish I get the following error.

    Error 13 There is no build provider registered for the extension '.ashx'. You can register one in the section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'. E:\Visual Studio 2005\WebSites\xxxxxx\Entertainment\Gallery.aspx 3

  • @Wil: check that the server has ASP.NET 2.0 or higher installed, then check the web.config file.

  • I am having the smae problem, able to debug, but publish.... ASP.net 2.0 is installed on my local machine, and the web config for the website had the build providers included.... Any other suggestions...

  • @Jeff: difficult to say without looking at the server. Drop me a mail through the contact form and I'll have a look.

  • Hello,
    I copied album.ashx and MetaDataExtractr.dll to directory with jpgs but I get this message:

    "Błąd serwera w aplikacji '/PhotoHandler-6410'.

    Błąd kompilacji
    Opis: Wystąpił błąd w czasie kompilowania zasobu wymaganego do obsłużenia tego żądania. Przejrzyj poniższe szczegółowe informacje o błędzie i zmodyfikuj odpowiednio kod źródłowy.

    Komunikat o błędzie kompilatora: CS0246: Nie można znaleźć nazwy typu lub obszaru nazw 'com' (czy nie brakuje dyrektywy „using” lub odwołania do zestawu?)

    Błąd źródła:

    Wiersz 52: using System.Web.UI.WebControls;
    Wiersz 53:
    Wiersz 54: using com.drew.metadata.exif;
    Wiersz 55: using com.drew.metadata.jpeg;
    Wiersz 56: using com.drew.metadata.iptc;"

    this line is red:
    Wiersz 54: using com.drew.metadata.exif;

    this: Komunikat o błędzie kompilatora: CS0246: Nie można znaleźć nazwy typu lub obszaru nazw 'com' (czy nie brakuje dyrektywy „using” lub odwołania do zestawu?)
    means: compilator error message: CS026: Could not find type name or namespace 'com' (check whether "using" is missing.

    Hope You'll help me.

  • @Bartek: it's hard for me to understand the localized error message but I'm suspecting you didn't put the dll into the bin directory of the web application.

  • i checked it once again and MetaDataExtractr.dl is in this directory;/

  • @Bartek: is the bin directory in a directory that is configured in IIS as a web application?

  • I assured that I put MetaDataExtractr.dll into the appropriate directory.;/

  • @Bartek: I believe you. The question I was asking was on the *parent* directory of bin. Is the parent of bin configured in IIS to be a web application? We can take that offline. Please contact me using the contact link.

  • Has anyone been able to get this into a DNN Module? Can I use this in DNN?

  • @Ty: I never tried, but if you use it as a user control, I don't see why not.

  • Is there any way to display the folders in date order and not alphabetically

  • @Dominic: it already is in date shot order. If that's not the case for your photos, maybe they are using an exotic EXIF tag. Feel free to send me one of those at bleroy at microsoft and I'll have a look.

  • I'm running the photo album on my Windows Home Server but I've run into problems with a few photos. Some photos shows as thumbnails but they are not shown in full size when I click the thumbnails. It seems like they won't load at all. If the photo doesn't load, the next thumbnail will not appear. If I open the photo in an image editor and save it with a new name, it seems to work.

  • Mine problem is all on godaddy when the default.aspx hit this line of code it stops

    If I remove it the style sheet loads, but obviously the ablum doesn't work.

    I can only get the original Album.ASHX to work. I an out of options until my contract with gofatty is up, cause I don't know what else to do.

  • Ok I got everything to run fine on my local machine. When I publish to my site hosted by Godaddy.com I get a problem with the following code. Apparantly they are not giving me rights to the temporary asp.net folder this is using. Thanks in advance for your assistance.

    Static IMagehelper()




    _imageCacheDir = Path.Combine(HttpRuntime.CodegenDir, "Album");


    This is the error:

    Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    I saw mention earlier that changing the Caching == CacheLocation.Disk to Caching == CacheLocation.Memory in the ashx file will work for godaddy. But I have tried changing all the string to memory and I still get the same error. I gues I am unsure on how to change the handler.

  • Hi Bertrand.
    Excellent work with this photo handler. Well done. I have just one question. I would like to display a subset of the EXIF meta-data. Ie.. If I wanted to view Model, Exposure and F-Number details. Is it possible?

    Dave OS

  • @Dave: sure, for the moment I'm just dumping all the available info but you could certainly modify the code to only display a subset.

  • Thanks. I've tried but to no avail. My skill set dos'nt include C# :(. Any idea where i can start?

    Dave OS

  • @Dave: if you go to GeneratePreviewPage, there is a double loop in there that loops over Image.Metadata. You could modify the code in there so that it continues the loop if the data is not in your predefined list. Something like if (!["OneKeyIWant", "AndAnotherOne"].Contains(data.Key)) continue;

  • Thanks for that Bertrand. I played around with it for a bit and got it working. Here it is below. I removed the qoutes from each side of the commas. :)

    if (!"Model, Exposure Time".Contains(data.Key)) continue;

    Again.... Thanks for your help.
    Dave OS

  • @Jeff: no, nobody is working of that that I know of. How would you keep up with new releases though?

  • Bertrand,

    You are correct, that is my dilemma. I am now looking for a option. Thanks for your response!

  • @Jeff: actually I'm not quite sure why you would want to do that in the first place. If you really want to do it, I'd at least wait for the next update, which will be quite major.

  • Hi,

    Can you please let me know "How do I make the code to select the Images present in a particular folder and subfloders present in that folder"?

    I mean to say "If I have placed a folder with the name ALBUMS and this folder ALBUM contains so many subfloders with the related images". So in this case how would I make the code to select the folders present only in the ALBUM Folder?

  • @babji.sunny: I'm not following you. The photo album already works with subfolders.

  • its very nice to use....thanks dude....

  • This is a cool app. Thanks for sharing it!

    Here is my question: Does this work if it's used with a Master Page? I am using a Master Page so that I have the same look on each page. It seems that the photo album is starting at the root of my web application and trying to grab images and directories from there. Have you ever tried this with a Master Page before?

  • @Jeremy: sure, it should work just fine with a master. You should be able to set the path property on the control to any directory you want.

  • how to change bgcolor of folder, I want white color..............
    pls tell me how to change....pls

  • Thanks for this quick an nice solution.

    It took me less than 2 minutes to get it up-and running.

    Nice application for jpg handling.

  • Awsome app, Worked great right off the bat additional user privledges needed to get the app creating its folder icons but I figured it out. Thanks for putting this together. Most companies are chrging through the nose for the ability to have a nice photo album on a website!

  • Hi, This looks great and something I think I can really use, but unfortunately I am encountering problems trying it on brinkster. Here is the error I am receiving. Any help you can provide is greatly appreciated. Thanks much in advance.

    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0246: The type or namespace name 'com' could not be found (are you missing a using directive or an assembly reference?)

    Source Error:

    Line 52: using System.Web.UI.WebControls;
    Line 53:
    Line 54: using com.drew.metadata.exif;
    Line 55: using com.drew.metadata.jpeg;
    Line 56: using com.drew.metadata.iptc;

  • @George: you probably didn't upload the dll into the bin folder of the application.

  • Hi, thanks for the quick response, but yes, I have uploaded the bin file to the application. Any other ideas?

  • Are you sure that bin folder is at the root of the configured IIS web application? (this is the only reason why you'd see that message)

  • Ahh ha... thanks again for the quick responses. I had the dll in the bin folder under the webroot folder. I just copied up the file album.ashx to my webroot folder though and it works fine there. I have not been able to get it to work in just a subdirectory yet though. I will try again tomorrow. Thanks very much for your assistance!! Great utility!!

  • Do you have a VB.NET Version?

  • @Tango: no.

  • Hi, this is great, but I can still only get it working in my webroot directory. If I put album.ashx in a sub folder I get the error "type or namespace com could not be found". I do have the dll in the bin folder of webroot though. Do you have any ideas on how I might resolve this? I really only want to display images from the subfolder. Thanks in advance.

  • some additional information... the version of the dll I am using is Thanks - George

  • @George: you can use the album as a user control and set its path property.

  • Hi great job. Working fine on mine. Just wondering if it is possible to have image titles or description added.

  • @miraz: that's failry easy if you use it as a user control (there are templates for precisely that), otherwise you can delve into the rendering code and add it.

  • Hi, I dont' mean to be a pain (fairly new to this), but where do I set the path and property? Do I do it in album.ashx? If so, do you know which line, or do you have an example. Thanks again very much in advance. Again, it works fine in my webroot, but I receive the error "The type or namespace name 'com' could not be found" when I try it in a sub directory.


  • @George: look at the sample that comes with the handler. It uses the handler as a control inside a page. You can set the path property on this control.

  • This is just what I needed! Thanks for sharing this wonderful app.

    I have close to zero experience with IIS and ASP.NET yet I was still able to get up and running in about an hour or 2 with help from these messages and google.

    I plan to create a mobile.ashx/aspx with smaller image dimensions so I can view my photos from anywhere on my phone.

    Thanks again.

  • I am a newbie and I have this handler up and running. I need to restrict the handler to pick up a specific directory. I have tried dropping the handler(album.ashx) in the specific directory but then when I run it, I get the thumbnails with red x's. I am simply trying to get the folder \Photos with Sub Dir's \Album1, \Album2, etc. to display without pulling from the root of the website. I have treid multiple configurations and seem to run into issues. It lloks like I can set the path in the control properties but that gives me another error ~/Photos/album.ashx. Please help!

  • @Rick: You don't *need* to use the page and control if you're not going to add stuff around the album or modify the templates. You can use just the handler on its own, and drop it into the photo directory.
    If you do want to use it as a control, the path must not point at the handler but rather at the photo path.

  • Got it working. Thanks! I did not realize that you could use the .ashx directly as a page. Is there a simple way to use this with an MSACCESS database BLOB for your pics?

  • @Rick: no, no database support, sorry, unless you add it yourself. But why would you want to do that? Is it an existing database that you have from which you want to extract pictures?

  • I'm looking for source code to extract metadata from jpeg file in IPTC format, please help with C# or VB.NET


  • @Rima: the metadata in the image files themselves is more than capable to do that, and the album handler already knows how to read that information. Adding an xml file seems unnecessary.

  • The issue I am having is that it creates the initial album perfectly, but I am pointing to a virtual folder through IIS and the script seems to set all the addresses as f/photos instead of /photos, so I cannot click on the thumbnails for the folders to look inside...any ideas?

  • @Nathan: I don't understand. Can you send me e-mail at bleroy at microsoft with some more details about what you're trying to do?

  • Is the CSS in the current version on codeplex the newest version? because the layout doesnt look the same as the one on those images, I think i have the same problem as posted by Martin Dolphin in the very first post here

  • @Rima: the library that I'm using currently doesn't support writing the meta-data back to the image files but that sounds like the right thing to do in principle (and I believe .NET now has read/write APIs for EXIF data). Storing that data in a database might get you there faster though.

    @greg: let's follow up offline on that.

  • I did not add the editing.. just added file upload, directories and files names editing and deleting.

    I still can't get this PATH attribute work.
    keeps getting:

    Value cannot be null.
    Parameter name: value

    on the line:
    if (path != _requestDir && !path.StartsWith(_requestPathPrefix)) {

    I can't use the default album.ashx, I need to edit the template.

    I have the images in a directory called: Gallery

    So I tried setting the path:

    And keeping the Register

    HELP :( :(

  • Same here... images in a subfolder and Path property wont work. where's the documentation for this thing?? nice application isn't so nice without docs.

  • how put paging in the photo thumbnails page..

  • Sir,
    Your Development (A simple ASP.NET photo album) is Excellent.
    But I need a Small thing.
    I Have Three Folders in my web directory,

    Folder 1: images (some JPG images are there)
    Folder 2: Products (some JPG images are there)
    Folder 3: Album
    Album_one (subfolder of Album)
    Album_two (subfolder of Album)

    I want this photo album is only applicable for
    Album folder and subfolders of Album_one, and Album_two.

    How to Change the code.

    Thank you.

  • @Shankar: no need to change the code, just put the handler in that Album folder.

  • If you want to use this with disk caching on godaddy and aren't afraid of using your disk quota, change the following in album.ashx.

    Line 209
    _imageCacheDir = Path.Combine(HttpRuntime.CodegenDir, "_imgCache");
    _imageCacheDir = Path.Combine(HttpRuntime.AppDomainAppPath, "_imgCache");

    and surround lines 1973-1985 with an if block like so
    if ((folder.Name.Equals("Album") || folder.Name.Equals("_hcc_thumbs")) == false) {
    // code from lines 1973-1985

  • I just moved this website to Godaddy. Of course the photo album was working own my own 2003 server no problem. Now its not showing thumbnails. I adjusted the album.ashx to use memory instead of disk but no luck. Can anyone help fix this? This is a great photo album and it seems from this post that some people may have gotten it to work at GoDaddy but maybe I missed something.

    Also I did change permissions on the IIS mgmt at GoDaddy and create and application for that folder. Its running IIS7

  • Actually, Tyson's post worked great. I must of had something wrong. Its working great now

    If you want to use this with disk caching on godaddy and aren't afraid of using your disk quota, change the following in album.ashx.

    Line 209

    _imageCacheDir = Path.Combine(HttpRuntime.CodegenDir, "_imgCache");


    _imageCacheDir = Path.Combine(HttpRuntime.AppDomainAppPath, "_imgCache");

    and surround lines 1973-1985 with an if block like so

    if ((folder.Name.Equals("Album") || folder.Name.Equals("_hcc_thumbs")) == false) {

    // code from lines 1973-1985


  • I am getting

    Error Creating Control - Album1Type 'System.Web.UI.UserControl' does not have a public property named 'FolderModeTemplate'

    when trying to view Templated.aspx in design view.

    MetaDataExtractor is referenced
    Templated.aspx, Default.aspx, album.ashx and Album.css are all in the same directory.

    In addition, the Default.aspx page works fine until I move the album.ashx file into a subdirectory and change the control path. In this case:


  • I got the control to work - you need to set the HandlerURL and Register Src="" to the same amount

    I have 1 question though

    I see 2 other people asked about the images showing up in a column. How do I change that so the control is only a shortcut image ot he directory where the album.asxh is located? Is that in the .css embedded in the class?

  • @Jamie: not sure I understand your question. Do you want to follow-up offline with me (bleroy at microsoft)?

  • I love the look and interface; works great with my site but only on my system. When I upoaded it to my web host, I do not have permissions as you stated in your discription.

    How can I change the cashing?

  • @Russ: do a search for "CacheLocation" in the code for the handler. Change the first line you find to:
    private const CacheLocation Caching = CacheLocation.Memory;

  • @Russ: not sure that's what you're asking, but you can put one handler in each of the folders.

  • Sorry for not being clear; I have 4 other sites that I host for friends of mine. They have pictures at appear on their site that I really do not want in my gallery. All site folders reside in the same main directory each URL pointing to each sites folder; my site resides intact in the same main directory. When the album is launched it shows pictures from all teh sites; I would like it to only search in the image folder.


  • @Russ: why don't you put a handler.ashx in each of the image directories?

  • I hate to say this but I am just learning ASP.net; I usually work with Frontpage, I trying to learn. I do not know how to put a handler.ashx on the image folders so that they are the only ones viewed. Can you tell me or send me a link?


  • @Russ: no problem, feel free to e-mail me at bleroy at microsoft.

  • When I try to set the Path, I get this error:

    Line 1562: }
    Line 1563:
    Line 1564: if (path != _requestDir && !path.StartsWith(_requestPathPrefix)) {
    Line 1565: ReportError("invalid path - not in the handler scope");
    Line 1566: }

  • @MR: the picture directories have to be "under" the directory where the album handler sits.

  • Got the ablum working on my home system but but once I upload it to my hosting server it reads "Click to Display" any ideas?


  • @Russ, I can't access your server for some reason, but you probably need to configure the handler to use memory caching instead of disk caching. See some of the previous comments.

  • Will this work with ASP.net 3.5?

  • @shaolin77: yes.

  • Hi, I have build a website with asp.net and would like to implement this album in it... I tried to add the ablum files (templated.aspx etcc files) by using the add existing item in the visual studio but when i build the solution it give me an error something about metadata... "com" missing. can someone please help me solve this problem? as i'm not a pro in asp.net

  • @Justin: you need to copy the dll that comes with the release into the bin folder of the application.

  • @Bertrand: You were telling Russ...

    @Russ: why don't you put a handler.ashx in each of the image directories?

    I am attempting to do this - using as a user control - with the following Directory Structure:

    Main Photos (album.ashx here, main.aspx with the @register src of ~/Main Photos/album.ashx, secondary.aspx with the @register src of ~/Main Photos/Secondary Photos/album.ashx, and tertiary.aspx with the @register src of ~/Main Photos/album.ashx)
    |__ Secondary Photos (album.ashx - HandlerUrl changed to ~/Main Photos/Secondary Photos/album.ashx)
    |__ Tertiary Photos (album.ashx - HandlerUrl changed to ~/Main Photos/Tertiary Photos/album.ashx)

    But when I drop the handler in the subdirectories, modify the HandlerUrl and compile the code I get the following errors in each of my .aspx pages as well as the compiled DLLs.

    Error 38 The type 'Bleroy.Photo.Album' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\photos\d81285ef\ee16f919\App_Web_lsjmicgf.dll' and 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\photos\d81285ef\ee16f919\App_Web_plpl094z.dll' c:\Projects\company\main.aspx 10

    I've never used .ashx files before so I feel like I may be missing something easy here... I tried renaming the namespaces to no avail. Any other suggestions?

  • @noonway: right, Web Application Projects are not something I've considered. On the other hand, if you're using it as a control, I'm not sure you need two copies. Pointing both controls to the same url should in principle work.

  • @Bertrand: But if I point both controls at the same URL I get the full Gallery list instead of just a particular gallery.

    What I'm trying to do is build a menu called Gallery that shows all the sub-galleries on one .aspx page but then if the user selects a particular Gallery from the menu it would only show that secondary gallery and not the main or tertiary galleries. I could probably recode the handler to take an argument with the directory I want to show, but I don't really have the time to delve that deeply into the code.

    Oh well, I guess I'll just use the single gallery and let the users select which sub-gallery they want to use directly from the main.aspx.

    Great work here, by the way. I never would have thought to use caching the way you did and appreciate the tutorial. :)


  • @noonway: well, that's not a scenario I had in mind. There is a new version on the way though and I can try to see what I can do, but I can make no promises about when that's going to be out.

  • "CS0246: The type or namespace name 'com' could not be found"

    I'm sure that the MetaDataExtractor.dll is loaded to the Bin directory .

    What is the problem ?

  • @Sayed Mohamed: I really think that is the problem. Are you sure the bin directory is directly under a directory that is configured in IIS to be an application?

  • Not sure if this has been answered, but a find/replace to replace ".jpg" with ".png" enabled support for png's. So yeah, that can be done.

  • I am having the same problem as Martin Dolphin (September 9, 2005) and Greg (on March 5, 2009) previously reported. That is, the default page background is not black and the photo stacks are in a single vertical line down the page. Since I just downloaded the package today, I would have thought that the CSS would be the correct version.

    Please help.

  • @Paco: it's not just CSS. I know the update is long overdue but it will come. In the meantime, I'm afraid your only option is to go into the code and fix it yourself.

  • @Bertrand: thanks for the quick reply.
    I'm surprised that it is not yet fixed. Given the long delay and few reports of problems, I thought that it was my problem. I'll see what I can do to help.

    Happy Thanksgiving.

  • Hello, I am trying to set this up on my home server. I have created the Root Web App, copied all of the files and folders to my photos directory and hav a link pointed to the virtual directory.

    I am receiving the following error: Server Application Unavailable
    The web application you are attempting to access on this web server is currently unavailable. Please hit the "Refresh" button in your web browser to retry your request.

    Any help would be greatly appreciated.

    PS - I am trying to get this running on Windows Home Server the directory for the photos is a UNC path to the WHS shared Photos folder.

    Thanks again

  • @Derek: never seen that happen with this app. Usually that happens when an app gets killed by the server because it went over some memory or stack limit. I suppose it could happen if you had some insanely big pictures in there. Try again with few small pictures, just to see.

  • Awesome little script!

    I need just one more thing and that is the file name (with or without extension) to be able to place it under the image..can someone show me the variable to use to pull that info?


  • Thanks for your share.
    Would you like to tell me
    How can I permit user to upload image to current folder?

  • @Jake: use FTP, file copy, or whatever way you have to access the site's file system. The application won't allow you to upload.

  • @Krish: it's in the settings. Look for "ThumbnailSize" near the beginning of the file.

  • @kris. Well, then you're on your own. Feel free to modify the code any way you want.

  • Dear sir,
    I put this in a asp.net solution and when the thumbnails of the folders are shown, the other folders like "obj" and "properties" are also shown as thumbnails. can u please tell me a way to remove those.. I guess i should change the path of folders. but i dont know how to?
    please help me Im a begginer. ..

    thanks in advance!!

  • @duminda: the simplest is probably to create a folder where you put nothing but the images and the handler.

  • I love this application! I do however also have the same question as RED, to find out how to get the name of the image under (or above) the picture.

  • How would i be able to let someone upload pic's and see it loaded in the album?

    i know i could use a uplaod commponent, but getting it to save?


  • @RJ: you can't, except if you give them ftp access or build it yourself.

  • Dear Sir
    I am a beginner in asp.net.
    I want to use this Photo gallery in my project.
    How can i do it?
    thanks in advance!!

Comments have been disabled for this content.