Getting image URL from image ID

Vote:
 

Hi,

I am using Page listing Block to list all the pages in the parent page. I am able to display all the properties of child except the image.

The image file property is displaying image ID.

@item.Property["Product_Image"].Value

Thanks

Pankaj

 

#118489
Mar 08, 2015 15:02
Vote:
 

Hi,

When you have image Id, you can get the ContentReference of the image, then use IContentRepository to load the content and use UrlResolver to get the public URL, which should be the path to the image.

Regards.

/Q

#118490
Mar 08, 2015 16:10
Vote:
 
@Url.ContentUrl(ServiceLocator.Current.GetInstance<IContentRepository>().Get<ImageData>(item.Property["Product_Image"].Value))
#118491
Edited, Mar 08, 2015 18:04
Vote:
 

Thanks Quan and Valdis, I was able to solve it using below:

@Url.ContentUrl(item.GetPropertyValue<ContentReference>("Product_Image"))
#118495
Mar 09, 2015 6:38
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.