I have a document field that uses the 'Image Selector' field type. This stores a NodeGuid identifier into the appropriate column for my document.
What functions are available to retrieve a SEO-friendly Url for the image using this Guid? I'm mostly concerned about use in a transformation.
I've seen various other posts about using functions like:
GetFileUrl("ArticleImage")
- which gives a Url like: /getattachment/829b3830-4802-45db-8a97-c591f3d7ba41/invest-in-spanish-real-estate-minister-urges-brits.aspx
or even using: ResolveUrl("~/CMSPages/GetFile.aspx?guid=" + Eval("ArticleImage").ToString())
- which gives an equally horrid: /CMSPages/GetFile.aspx?guid=829b3830-4802-45db-8a97-c591f3d7ba41
Since these image files are in the hierarchy and are documents on their own, they have the nice Kentico Url properties like 'Document Url Path' and various 'Document Aliases'. So I'd like to easily get the 'Document Url Path' for the image, along with the file extension - something like: /Images/big-blue-image.jpg for a url.
I've gone and made my own custom Function, but I think that this has already got to be in the framework, but I just don't know where to find it.
public static string GetImagePathFromGuid(object guid)
{
if (null != guid && !String.IsNullOrEmpty(guid.ToString()))
{
//lets use this to get a 'cleaner' SEO-optimal Url
Guid g = Guid.Parse(guid.ToString());
CMSContext.Init();
UserInfo ui = UserInfoProvider.GetUserInfo("administrator");
var tree = new CMS.TreeEngine.TreeProvider(ui);
var node = tree.SelectSingleNode(g, CMS.CMSHelper.CMSContext.CurrentDocument.DocumentCulture, CMS.CMSHelper.CMSContext.CurrentSiteName);
return node.DocumentUrlPath;
}
//default
return null;
}
Any ideas?
Cheers,
Lance