For use in Microsoft SharePoint Foundation 2010 and SharePoint Server 2010, this Picture Thumbnails Web Part displays images from a SharePoint Picture Library in a widget-like thumbnail layout (see Figure 1). When a user clicks on a thumbnail, the original image opens up Lightbox style on top of the darkened page (see Figure 2). This is adapted from my WSS 3.0 version for SharePoint 2010.
For images stored in a SharePoint Picture Library, thumbnails are generated by referencing the URL /<Picture Library Url>/_t/<Image Name>_<Image Extension>.jpg. This URL is stored in field
EncodedAbsThumbnailUrl. However the thumbnails are too big for my liking. Instead of using some custom HTTP handler to generate thumbnails of smaller size, I decided to use the thumbnails as they are but use them as CSS background images. This way, I can control the "apparent" thumbnail size by sizing the block element associated with the background image, thereby avoiding any aspect ratio issue of just resizing the thumbnail images directly.
Next, I would like to have some Dynamic HTML or Ajax functionality to view the original image when user clicks on a thumbnail. Lightbox style preview looks very cool to me. There are many implementations or variations of Lightbox and I settled on using Litebox because of its compact size and relatively small number of supporting files.
PictureThumbnailsWebPart functions as a wrapper by calling custom web control
PictureThumbnails. This design allows the developer the option to add the web control directly to a master page or a publishing page layout where Web Parts are not allowed. The Web Part has the following
SiteUrl - (Site URL) Server relative URL of the site. If left blank, current site is used.
ListName - (Picture Library Name) Name of a Picture Library in the current site.
SortField - (Sorting Field) Available options are
SortOrder - (Sorting Order) Available options are
Random is selected,
SortField will be ignored.
RowLimit - (Maximum Number of Pictures) Default is
0, which means no limit.
ShowAsImageSet - (Group Images into a Single Set) Default is
false. If set to
true, all images will be treated as part of an image set in Litebox, allowing previous and next navigation during preview.
CssClassPictureThumbnails - (CSS class)
The Lightbox functionality is provided by Litebox and requires a number of supporting files:
- litebox-1.0.js, moo.fx.js, prototype.lite.js.
Page.ClientScript.GetWebResourceUrl, passing in the files in the form of
[Default namespace].[Folder containing resource].[Filename of resource]. In AssemblyInfo.cs, include each of these files in the same format. For example:
- blank.gif, closelabel.gif, loading.gif, nextlabel.gif, prevlabel.gif
These images are treated as Class Resources. In code, the path to Class Resource files is obtained by calling
SPWebPartManager.GetClassResourcePath. Since the project assembly is deployed to GAC, the deployment path will be something like /_wpresources/QuestechSystems.SharePoint.Thumbnails/220.127.116.11__ce574b585167cfb8/. To package Class Resource files for deployment, a SharePoint 2010 Empty Element is created in Visual Studio 2010. These images are added under the newly created folder with Deployment Type set to ClassResource.
- lightbox.css, picturethumbnails.css
You can find them in the Styles directory. lightbox.css is customized from the original Litebox module to reflect the directory path of Class Resource images. If you recompile the supplied Visual Studio project with your own strong name key file, you would need to update these paths. picturethumbnails.css is not part of Litebox but is required for the widget/thumbnail look and feel as shown in the screenshots above.
The Web Part also uses a resource file to store all messages and property attribute UI strings. It demonstrates how to develop a custom class that inherits
CategoryAttribute and returns a localized
string from your own Resource Manager.
The supplied Visual Studio 2010 solution includes all the support files you need to build and deploy this Web Part, minus the strong name key file (key.snk). It makes full use of the built-in SharePoint integration. No more third party tools or custom pre and post build scripts are needed to build the SharePoint solution file.
Open SharePoint 2010 Management Shell, add solution file QuestechPictureThumbnails.wsp using
stsadm, add solution file QuestechPictureThumbnails.wsp like:
stsadm -o addsolution -filename "C:\QuestechSystems.PictureThumbnails\bin\
Go to SharePoint 2010 Central Administration/System Settings/Manage farm solutions. Deploy the installed solution to selected web applications. In the site collection where the solution is deployed, activate the Site Collection Feature Questech Systems Picture Thumbnail Web Part. After that, the Picture Thumbnails Web Part (listed under Questech Systems) should be available for you to add to pages.
As mentioned, the Lightbox functionality depends on lightbox.css and picturethumbnails.css. If you have a custom CSS file for your site already, you could just copy the content out from the two files and paste it into your custom CSS. If you do not have a custom CSS file, you would need to either add it through the SharePoint UI Site Settings interface or insert it in your custom master page or page layout (for SharePoint Server 2010).
Tips: You can control the number of thumbnails shown per line by adjusting the width of the Web Part.
Please note that though this web part is licensed under The Code Project Open License, Litebox is licensed separately under Creative Commons Attribution 2.5.