SharePoint Picture Library URLs 

Tags:

I recently created a web part for a client that shows a slide show from a picture library using the Slide Show Extender from ASP.NET AJAX Control Toolkit. This requires creating a web service that returns an array of slides, each of which has a URL to a picture.

Amazingly, the most time consuming part of this was determining the URL for a thumbnail image from a picture in a picture library. There may have been a better resource, but I found the hints I needed here: http://msdn2.microsoft.com/en-us/library/ms413130.aspx.

Since this was painful enough, I thought I would post my solution so that others may benefit. Below is the source needed to get the URL for the full image, the larger size (the one you see when viewing or editing an individual picture library item), or the thumbnail size.

    using Microsoft.SharePoint;

    using Microsoft.SharePoint.Utilities;

    <namespace and class definition here…>

    public enum ImageSize

    {

        Thumbnail,

        Large,

        Full

    }

    /// <summary>

    /// Provides the url to a picture provided the picture library list item.

    /// </summary>

    /// <param name="item"></param>

    /// <param name="imageSize"></param>

    /// <returns></returns>

    /// <remarks>

    /// Ugly, but see: http://msdn2.microsoft.com/en-us/library/ms413130.aspx - there doesn't seem to be a better way.

    /// </remarks>

    public static string GetPictureUrl(SPListItem listItem, ImageSize imageSize)

    {

 

        StringBuilder url = new StringBuilder();

 

        // Build the url up until the final portion

        url.Append(SPEncode.UrlEncodeAsUrl(listItem.Web.Url));

        url.Append('/');

        url.Append(SPEncode.UrlEncodeAsUrl(listItem.ParentList.RootFolder.Url));

        url.Append('/');

       

        // Determine the final portion based on the requested image size

        string filename = listItem.File.Name;

        if (imageSize == ImageSize.Full)

        {

            url.Append(SPEncode.UrlEncodeAsUrl(filename));

        }

        else

        {

            string basefilename = Path.GetFileNameWithoutExtension(filename);

            string extension = Path.GetExtension(filename);

            string dir = (imageSize == ImageSize.Thumbnail) ? "_t/" : "_w/";

            url.Append(dir);

            url.Append(SPEncode.UrlEncodeAsUrl(basefilename));

            url.Append(SPEncode.UrlEncodeAsUrl(extension).Replace('.', '_'));

            url.Append(".jpg");

        }

 

        return url.ToString();

    }

 

 
Posted by Kirk Liemohn on 13-Sep-07
5 Comments  |  Trackback Url  |  Link to this post | Bookmark this post with:        
 

Links to this post

Comments


wow commented on Thursday, 30-Oct-2008
lc Welcome to wow gold. We are a world class wow powerleveling store online. We supply cheap wow gold to our loyal and World of Warcraft goldreliable customers. you canwow power leveling buy really cheapwow gold wow gold here. We havewow power leveling mass available stock ofwow power leveling wow gold onwow power leveling most of the servers, sowow power leveling that we can do aRolex really instant way of wow power levelingwow gold wow golddelivery. We canwow powerleveling deliver yourwow powerleveling wow gold on powerlevelingthe order powerlevelingin a short cheap wow goldwhile. We have beencheap wow gold an ebay powerpower leveling seller and paypalpower leveling confirmed seller rolex replicaof wow gold for replica rolexyears.So it ischeap wow gold securest and safestRunescape Gold to buy RuneScape Money wow gold from Watches Rolexus. Don’t be Rolex Watchesirresolute! We arewow gold hoping to servegold wow you and helpingWatch Rolex you to have a wonderfulRolex Watch wow life! We arers gold ready now, how about you?


nana commented on Wednesday, 12-Nov-2008

car wash commented on Monday, 29-Dec-2008

car wash commented on Monday, 29-Dec-2008
Pursestock supplier provides the best Gucci replica,Chanel replica,Louis Vuitton replica; show you every detail of photos of replica handbags. Do you think it is hard to believe that we have such a high-quality wholesale replica handbags,Hermes birkinand Hermes kelly? Let me tell you, when you have our Gucci replica purses, you will understand why Chinese manufacturing industry and replicas products are so well-developed. The authentic Gucci replica, you can buy for collections. But the genuine high prices are outrageous, how many collections you can buy with such a high price,if you like Monogram Canvas,speedy 30,chanel 2.55 bag ? Jadeshow’s replica Tiffany Jewelry and Replica Bvlgari Jewelery looks just like the real thing. Why pay more for a single piece of Tiffany Replica jewelry,Bvlgari Replica Jewelry when you can treat yourself to a number of replica pieces for the same price or less? Be simply spectacular with contemporary Tiffany-inspired jewelry!Jadwshow delights in the opportunity to offer our customers fine Tiffany Bracelets, Tiffany Necklaces, Tiffany Earrings, Tiffany Rings, Tiffany Bangles,Gucci jewelry replica, all at remarkably low prices.

Name:
URL:
Email:
Comments:

CAPTCHA Image Validation