Thumbnail url of the news item

Posted by Community Admin on 04-Aug-2018 15:31

Thumbnail url of the news item

All Replies

Posted by Community Admin on 01-Jun-2015 00:00

Hi All,

I am having a newsitem object and i need to get the url of the thumbnail image of that particular news item. Here is the code i am using:

 

public string GetNewsImage(NewsItem item)
       
           string imageUrl = string.Empty;
           if (item != null)
           
               var relatedItems = item.GetRelatedItems("Thumbnail");

               var thumbNail = relatedItems.FirstOrDefault();
               if (thumbNail != null)
               
                   LibrariesManager lb = new LibrariesManager();
                   try
                   
                       var image = lb.GetImage(thumbNail.Id);
                       if (null != image)
                           imageUrl = image.ItemDefaultUrl;
                   
                   catch(Exception ex)
                   

                   
               
           
           return imageUrl;
       

 

But i am not getting all the images with the correct path. Some of the images are not getting the right path using this method. What am i doing wrong. PAny help or hint.

 

Thanks in advance!!

Anju Raman

Posted by Community Admin on 04-Jun-2015 00:00

Hello Anju,

Can you please tell me whether you are using related media field in the news module of your project? If this is correct you can check the following documentation article:

Query item relations using ContentLinksManager

Regards,
Kaloyan
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed