Search code examples
kentico

Kentico 9 transformation page/file URL


In my custom page type, you can select an uploaded file. That's fine, but in my ascx transformation, i'm having a hard time getting the URL. The field is 'Process'.

Here's what i currently have.

<%# IfEmpty(Eval("Process"),"N/A","<a href=" + Eval("Process") +" target='blank' class='icon download'>Download</a>")%>    

When rendered, the html is this:

<a href="214b6876-cb39-4a58-813f-19dcb7c788e4" target="blank" class="icon download">Download</a>

I'm missing something.


Solution

  • You can use either of the 2 methods below. Both have their downfalls though.

    <a href="<%# GetFileUrl("Process", "Something") %>"Link here<a/> this will

    Downfall with this is if there is no value in the "Process" field, it will return an invalid URL. So I tend to use something a little better (but not much)

    <a href="/getattachment/<%# ValidationHelper.GetGuid(Eval("Process"), Guid.Empty) %>/<%# ValidationHelper.GetString(Eval("NodeAlias"), "download") %>">Item to download</a>

    This will create a valid URL with some invalid properties to it. Meaning if there is no value in the Process field, it will return 00000000-0000-0000-0000-000000000000. If the NodeAlias field is empty, it will return "download". So again, not 100% fool-proof but it works well in most cases.

    Update
    Check out this link:
    https://devnet.kentico.com/articles/options-for-file-fields-in-structured-data

    I think the piece you need in here is in the "CMS.File page type" section:
    <a href="<%#GetDocumentUrl("FileField ", "kenticopicture")%>">This is the link to the picture</a>