Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Retrieve image using GUID in code behind View modes: 
User avatar
Member
Member
rob.maas-itelligence - 11/2/2010 5:35:31 AM
   
Retrieve image using GUID in code behind
Dear readers,

I'm figuring out how to retrieve an image using its database GUID in C# code behind.
I've tried using the GetImage method in the CMSAbstractTransformation class, but with no luck (it returns a null reference exception).

Does anybody know how to do this?

Thanks in advance!

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 11/2/2010 6:24:00 AM
   
RE:Retrieve image using GUID in code behind
Hi,

You can find an inspiration in the following code. This code creates an relative URL path to the 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