PageData GetRelatedItems giving item not found error

Posted by Community Admin on 04-Aug-2018 00:18

PageData GetRelatedItems giving item not found error

All Replies

Posted by Community Admin on 30-Sep-2014 00:00

I've having a problem when calling GetRelatedItems<Image>("fieldname") on a PageData variable. For the page in question, I'm sure that the related item is there, but it was never found. This related item is a custom field for all pages.

So I turned it around and retrieved the image id from the ContentLinksManager:

ContentLinksManager contentLinksManager = ContentLinksManager.GetManager();
LibrariesManager librariesManager = LibrariesManager.GetManager();
var imageId = contentLinksManager.GetContentLinks( )
  .Where( l => l.ParentItemId == parent.NavigationNodeId )
  .Select( x => x.Id)
  .FirstOrDefault();

 'parent' it the above snippet is a PageData variable. This returns the Guid of the image. Then I call:

Image imageItem = librariesManager.GetImage( imageId );

I'm getting a Telerik.Sitefinity.SitefinityExceptions.ItemNotFoundException at this point.

The strange part is that if I get the same page, but use the PageNode type, the related item is retrieved normally. As in here, where 'page' is a PageNode variable:

var imageItem  = page.GetRelatedItems<Image>( "LandingPageMenu")
  .FirstOrDefault();

This thread is closed