Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Using document selector in transformation View modes: 
User avatar
Member
Member
sam-isleofmanadvertising - 10/25/2010 7:09:35 AM
   
Using document selector in transformation
I've created a new doctype with a document selector field, and I'm now trying to retrieve this data in a transformation so that I can create a link to the document the user selects. However, I can't work out what method to call in the transformation to get the full document link - everything I try leads to a 404 error.

User avatar
Member
Member
kentico_michal - 10/26/2010 6:55:41 AM
   
RE:Using document selector in transformation
Hi,

You could use standard <%# GetDocumentUrl("NodeGUIDColumn", "NodeAlias") %> method. This method returns URL, that contains GUID, so from SEO point of view is better to use different approach.
I would recommend you to use following custom method in transformation. Please find more information about adding custom functions to transformation in Developer’s guide :
http://devnet.kentico.com/docs/devguide/index.html?adding_custom_functions_to_transformations.htm

public static string GUIDtoURL(object inputGUID)
{
string txtGUID = (string) inputGUID;
Guid guid = new Guid(txtGUID);
if (guid != null)
{
int nodeid = CMS.TreeEngine.TreePathUtils.GetNodeIdByNodeGUID(guid, CMS.CMSHelper.CMSContext.CurrentSite.SiteName);
CMS.TreeEngine.TreeNode node = CMS.CMSHelper.TreeHelper.SelectSingleNode(nodeid);

return CMS.CMSHelper.CMSContext.GetUrl(node.NodeAliasPath, node.DocumentUrlPath, CMS.CMSHelper.CMSContext.CurrentSiteName);
}
return "";
}


You could use following string to execute this custom method in transformation
<%# MyFunctions.GUIDtoURL(Eval("documentSelectorField")) %>


Best regards,
Michal Legen

User avatar
Member
Member
mwladika-sfopera - 1/10/2011 6:59:03 PM
   
RE:Using document selector in transformation
Hi Michael,

I have tried your suggested fix, but the URLs returned by this funciton have "~/" prefixed and I need a simple relative URL. I'm guessing it's something in the parameters, but cannot see where.

Any help?

Thanks,
Mark

User avatar
Member
Member
kentico_michal - 1/11/2011 9:21:11 AM
   
RE:Using document selector in transformation
Hi Mark

Have you tried to use following code:

<a href="<%# GetDocumentUrl("DocumentSelectorField", "NodeAlias") %>" > Link</a>

The prefix ~ should be replaced automatically with the domain name and the link should be generated correctly.


Best regards,
Michal Legen

User avatar
Member
Member
mwladika-sfopera - 1/11/2011 12:05:38 PM
   
RE:Using document selector in transformation
Hi Michal,

We did try that, but that function returns a url of this format:

~/getdoc/e19b1c47-119c-4998-8b55-78a24f25a674/NodeAlias.aspx

I tried playing around with the parameters, seems like the second one simply becomes the filename at the end. I cannot find any documentation on this function.


User avatar
Member
Member
kentico_michal - 1/13/2011 3:16:07 AM
   
RE:Using document selector in transformation
Hi Mark

It seems to me that your output filter is disabled. So to deal with this problem, could you please try using ResolveUrl method:

<%# CMS.GlobalHelper.UrlHelper.ResolveUrl(GetDocumentUrl("DocumentSelectorField", "NodeAlias")) %>


Moreover, you are right the second parameter simply becomes the filename at the end.

Best regards,
Michal Legen