This article shows how to display a user friendly link without GIUD to the document or file which was uploaded to some document as an attachment (e.g. on the Form tab using file upload form control). The Document Selector field type is storing only the GUID of the attachment.
If you want to display the alias path according to the given GUID number it is recommended to create the custom function called later in the transformation that would handle this task. Please visit the
www.kentico.com/docs/devguide/adding_custom_functions_to_tra.htm where process of creating function for transformation is described. In your custom function you would call the
"CMS.TreeEngine.TreeProvider.SelectSingleNode(Guid, String cultureCode, String siteName)" where you pass your GUID value, the culture code as the
"CMSContext.CurrentPageInfo.DocumentCulture" and the site name as the
"CMSContext.CurrentSite.SiteName". Returned
TreeNode object should contain all necessary information that could be returned to and displayed by the transformation.
In Visual Studio create new Class under
<your project>/App_Code and call it e.g.
MyFunctions.cs. Add following code to your new class:
public static class MyFunctions
{
public static string ReturnUrlSrc(string nodeGuidParam)
{
try
{
if (nodeGuidParam != null && nodeGuidParam.Trim() != "")
{
string nodeGuidStr = ValidationHelper.GetString(nodeGuidParam, "");
Guid nodeGUID = new Guid(nodeGuidStr);
if (nodeGUID != null)
{
int nodeId = CMS.TreeEngine.TreePathUtils.GetNodeIdByNodeGUID(nodeGUID, CMS.CMSHelper.CMSContext.CurrentSiteName);
if (nodeId != null)
{
CMS.TreeEngine.TreeProvider tp = new CMS.TreeEngine.TreeProvider(CMS.CMSHelper.CMSContext.CurrentUser);
CMS.TreeEngine.TreeNode node = tp.SelectSingleNode(nodeId);
return AttachmentManager.GetPermanentDocUrl(nodeGUID, node.NodeAlias, CMSContext.CurrentSiteName);
}
}
}
return "";
}
catch
{
return "";
}
}
}
Also please add following code to your transformation :
<a href="<%# MyFunctions.ReturnUrlSrc(Eval("DocumentSelectorField ").ToString()) %>">LINK</a>
where
MyFunctions is file name of your new class.
See also:
Applies to:
Kentico CMS 3.x
Created on 9/3/2008 7:35:51 AM