How to display a File image in search results transformation

   —   
This knowledge base article shows you how you can display a File image in the search results transformation using custom transformation method.
The GetImage method, which you are probably familiar with, does not work in search results transformation in case fields of File type simply because the search results dataset does not contain GUID of the file. In order to deal with this limitation, you will need to create a custom transformation method and use it in the transformation instead of the GetImage method.
This method could look like the following one:

public static string getFileImage(object inputGUID)
{
Guid guid = CMS.GlobalHelper.ValidationHelper.GetGuid(inputGUID, Guid.Empty);
if (guid != Guid.Empty)
{
string url = CMS.FileManager.AttachmentManager.GetAttachmentUrl(guid, "picture");
return "<img alt=\"" + "alternative text" + "\" src=\"" + url + "\" border=\"0\" />";
}
return "";
}


To execute it, you can use the following expression:

<%# MyFunctions.getFileImage(GetSearchValue("FileImage")) %>

-ml-


See also: Adding custom functions to transformations
Smart search transformations

Applies to: Kentico CMS 5.5R2
Share this article on   LinkedIn