Before having fun contemplating the essence of Globals.GetSiteUrls().UrlData.FormatUrl(name, parameters) with my latenight geek hours in preparation for SiteUrls on a Plane at CC6 in a couple of weeks, I wanted to dress up my Photo Galleries area a bit first. It frustrated me that I had to remove the SlideShow control (now back online) and it drove me nuts that I wasn't able to support an individual Album permalink (now can do.)
From CS 2.1 day one I had replaced the sidebar album listing with a dropdown list and a cookie to preserve state, shown here.
This worked fine, but I couldn't support a Url to display a single album listing. Adding simple querystring logic and a new GalleryUrl did the trick. The new GalleryUrl is below followed by the url as entered in the SiteUrls.config.
public virtual string ViewDBVTGallery(string applicationKey, int categoryID)
{
return FormatUrl("gallery_ViewDBVTGallery", applicationKey, categoryID);
}
<url name="gallery_ViewDBVTGallery" location = "galleries" path="##photogallerydirectory##default.aspx?catid={1}" pattern="##photoGalleryName##/default.aspx?catid={1}" vanity="viewGallery.aspx?App=$1&catid=$2" />
This also enabled another change I wanted to make while I was at it, which was to display the Album on the individual Picture Details display rather than the photo name. I never name my photos as there are just too many of them. The picture details page previously displayed a filename as a header (something like "IMG1007009.jpg" - worthless) and no album was shown anywhere to provide context. I replaced the image filename with an ASP:Hyperlink displaying the photo's album title using the new GalleryUrl above.
CategoryLink.Text = postCategory.Name;
CategoryLink.NavigateUrl = GalleryUrls.Instance().ViewDBVTGallery(cSContext.ApplicationKey, postCategory.CategoryID);
What was interesting about this was obtaining the Category (album) of the photo to pass to the category hyperlink. Photos are like blog postings in that they can be assigned multiple categories, or tags, so you aren't normally looking for a single category. I assign all of my photos to a single category, however, so all I needed was the first category returned. And here, once again, all of the groundwork is laid in Community Server to retrieve whatever it is we need. To retrieve the category of the current photo I created a GalleryPost object and retrieved a PostCategory cast of the GetPictureCategories() zero-index arraylist item. Two lines of code, baby.
GalleryPost gp = GalleryPosts.GetPicture(cSContext.PostID, true);
PostCategory postCategory = (PostCategory) GalleryPosts.GetPictureCategories(gp)[0];
Now, back to a serious study in SiteUrls.