Get image url from Document Image Upload Field

mun yung kan asked on January 28, 2015 05:47

Hi guys,

First time developing for kentico(8.1). i'm stumped as to how to get an image's url from an upload field on a document.

I have chosen to use aspx development in visual studio (beyond my control).

I have created a carousel web part, and associated it with ascx file.

I also created a page type called carousel. It has fields such as text, page selector and file upload(named image).

In the ascx, i have a repeater surrounded by the necessary html my front enders have created.

In the code behind, i make a query for carousel page types that exist in the content tree

`var carousels = DocumentHelper.GetDocuments("mysite.Carousel")
                           .OnSite("mysite")
                           .Path("/Carousels/%")
                           .Page(0,5);`

i bind these treenodes to my repeater

in my repeater i have access to my treenode and need to get a url for my image.

using treeNode.GetValue<string>("Image") i can only get the GUID of the image that was uploading into the document using the field.

so my questions are:

how do i convert this guid into an image url? is there a better way to do this?

everything i've found in the documentation tells me to use transformations <%#GetImage("fieldname")%>. Am i able to use transformation code in development via visual studio?

also what is the difference between attachments to a document (has kentico 8.1 renamed documents to pages?), and file uploads defined in a page type?

sorry for the scatter brained questions, my google fu and researching the devnet documentation has finally hit a brick wall.

Correct Answer

Brenden Kehren answered on January 28, 2015 15:16

In your ItemTemplate for the transformation you can use as you mentioned or you can also use this:

<img alt="<%# Eval("DocumentName") %>" src="<%# GetFileUrl("Image") %>" />

File or direct uploads are stored as attachments with a reference to the page type.

Attachments are uploaded and stored as attachments with a reference to the document.

Really close to the same thing as far as storage, just retrieve them differently.

1 votesVote for this answer Unmark Correct answer

Recent Answers


mun yung kan answered on January 28, 2015 16:34

thanks for than Brenden! makes sense about the attachments on pagetype and attachment on document now.

as for getting the url of an image from code-behind. are transformation methods available directly in the .ascx files? i've tried using them, but i get compilation errors, so i'm guessing i am not referencing the right stuff. either that or transformations were not designed to be used this way?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on January 28, 2015 16:42

Are you inheriting the CMSAbstractWebpart class on your user control? If not, then you most likely won't find those. Since you are using aspx development mode, you can still use transformations within your controls. All you need to do is specify the transformation code name like so namespace.class.transformationname and manage those transformations within Kentico.

1 votesVote for this answer Mark as a Correct answer

mun yung kan answered on January 30, 2015 02:38

thanks again brenden.

i am inheriting CMSAbstractWebpart in the codebehind class file.

i'm having difficulty locating the namespace/classes of the transformations in kentico 8.1

would you happen to have an example of where i need to reference to get the GetImage() method?

0 votesVote for this answer Mark as a Correct answer

harshal bundelkhandi answered on October 6, 2016 08:55

Hi Brendon,

I am uploading the images on Amazon s3 storage. in transformation i am getimage method to call the images.but while exporting & importing website to from dev to stg server server . i am getting broken image url link.

can you please suggest for the same.

Regards, Harshal

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.