Mark Handy
Mark Handy

Reputation: 1256

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.

Upvotes: 0

Views: 580

Answers (3)

Brenden Kehren
Brenden Kehren

Reputation: 6117

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>

Upvotes: 2

Trevor F
Trevor F

Reputation: 1437

See the "Transformation reference" link on your Trasnformation editor, it goes to all the available transformation methods you can use.

In it it shows:

This will generate an actual image tag. If however you want a link, it usually is

/getattachment/<%# Eval("TheImage")%>/ImageFileNameCanBeAnythingThough.jpg

example: /getattachment/1936c69d-a28c-428a-90a7-09154918da0f/Christmas.jpg

Upvotes: 0

Zach Perry
Zach Perry

Reputation: 756

Check out transformation methods reference

You can use <%#GetImage(Eval("Process"))%>. This will return an Image tag. There are a couple other parameters for sizing if you want to use those.

Upvotes: 0

Related Questions