Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Image selection code behind View modes: 
User avatar
Member
Member
gatsby0121 - 6/14/2011 10:31:44 AM
   
Image selection code behind
I have a webpart that uses an image selection field.

What's the code behind function to retrieve the url of the image. I have only been able to find the transformation code, which isn't what I'm looking for.

User avatar
Member
Member
gatsby0121 - 6/15/2011 6:58:29 AM
   
RE:Image selection code behind
To further clarify, this works in a transformation for the document using image selection:

<img src="<%# GetDocumentUrl("HeaderImage", "") %>" />

But I have an image selection in a webpart, and I'd like to be able to display that on pages where I use the webpart, which is why I need the c# code to resolve an image selection field.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 6/15/2011 7:53:22 AM
   
RE:Image selection code behind
Hi,

The image selector field returs GUID and you can use following code to create path to image:


Guid iguid = new Guid("98de82d1-5eec-46cd-b491-42a31f31e1d2");

// Tree node
CMS.TreeEngine.TreeNode node = null;

// Tree provider
UserInfo ui = UserInfoProvider.GetUserInfo("administrator");
CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);

// Get Single node specified by it`s GUID, culture code, site code
node = tree.SelectSingleNode(iguid, "en-US", "CorporateSite");

image.ImageUrl = "/Virtual_server_name_if_you_use_some"+ node.NodeAliasPath + ".aspx";



Best regards,
Ivana Tomanickova