Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Get Image Path in Transformation View modes: 
User avatar
Member
Member
robert-tailor.co - 9/13/2012 5:30:55 PM
   
Get Image Path in Transformation
Hi,

How can I retrieve the path to an uploaded image/file in a document type?

I have a document type with a File -> Uploader -> Direct Uploader field, called 'NewsTeaser'. I am retrieving the contents of this field in a Transformation:

<img src="<%# Eval("NewsTeaser") %>" alt="<%# Eval("NewsTitle",true) %>" />


Eval("NewsTeaser") does not resolve to the path to the uploaded file - it just resolves to the GUID of the uploaded file.

I can't use GetImage("NewsTeaser"), because I need to customize the attributes of the rendered <img> tag.

What other options are available?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 9/14/2012 2:12:18 AM
   
RE:Get Image Path in Transformation
Hi,

You can follow this idea using this API (those are older KBs so some API might have changed but the idea is still the same).

Best regards,
Juraj Ondrus

User avatar
Member
Member
robert-tailor.co - 9/16/2012 11:53:10 PM
   
RE:Get Image Path in Transformation
kentico_jurajo wrote: Hi,

You can follow this idea using this API (those are older KBs so some API might have changed but the idea is still the same).

Best regards,
Juraj Ondrus

Hi Juraj,

Although those URLs work, they both seem way over the top to just get the URL of an attached file. That article specifies how to generate a link without a GUID, but I really don't care whether the GUID is visible or not. The second link requires creating an instance of the AttachmentInfo class after jumping through lots of hoops beforehand.

Is there a reason why Kentico's API doesn't just provide a simple .GetAttachmentUrl(attachmentGuid) method?

I could be wrong, but I would have thought that returning the URL of an attached file was a fairly common CMS function.


User avatar
Kentico Support
Kentico Support
kentico_jurajo - 9/17/2012 12:47:15 AM
   
RE:Get Image Path in Transformation
Hi,

In this cas you can use the methods mentioned by Jiveabillion or just look to the default transformation, e.g. for the CMS.File document type there are attachments transformations and you can use e.g.: GetImage, GetFileUrl, GetAttachmentUrl, in cas of images GetImage functions.

When editing a transformation, at the bottom there is a link to all available functions for transformations (/CMSHelp/index.html?newedit_transformation_methods.htm).

Best regards,
Juraj Ondrus

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 9/14/2012 3:00:08 PM
   
RE:Get Image Path in Transformation
I usually use K# and text templates where I just use this {%GetFileUrlByGuid(ColumnName,NodeAlias)%}

in ASCX transformations, you can do this

<%# GetFileUrl("NewsTeaser") %>