1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / News item thumbnail??

News item thumbnail??

7 posts, 0 answered
  1. sam
    sam avatar
    102 posts
    Registered:
    31 Jan 2008
    28 Aug 2009
    Link to this post
    Hi,

    I have a piece of code that uses the NewsManager to retrieve all news items.

    public static IList GetNews() {  
            IMetaSearchInfo filter = new MetaSearchInfo(MetaValueTypes.DateTime, "Publication_Date", DateTime.Now, SearchCondition.LessOrEqual, JoinType.And);  
            NewsManager manager = new NewsManager(NewsManager.DefaultContentProvider);  
            return (IList)manager.Content.GetContent("Publication_Date desc", filter);  
        } 

    I am having a problem although with getting the correct path for the thumbnail of a news item.

    IList news = News.GetNews();  
     
            if (news.Count > 0)  
            {  
                IContent content1 = (IContent)news[0];  
                newsTitle1.InnerText =  
                    string.Format("{0}..", TruncateTitle(content1.GetMetaData("Title").ToString()));  
                  
                summaryLiteral1.Text = TruncateSummary(content1.GetMetaData("Summary").ToString());  
     
                if (content1.ThumbnailUrl != string.Empty)  
                    newsImage1.ImageUrl = content1.ThumbnailUrl; 


    e.g Thumbnailurl property is returning:
    /09-08-28/test_news_3.tmb.ashx
    but that is bringing up a 404.

    The thumbnail is question can be found using:
    Libraries/News/image01.sflb

    but the news IContent item returning the news item doesn't supply the Libraries/News/image01.sflb url.

    Any ideas??
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    28 Aug 2009
    Link to this post
    Hello sam,

    ThumbnailUrl property is uses only from Libraries provider where you have thumbnail mode of the images. You cannot use this property for news content items.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. sam
    sam avatar
    102 posts
    Registered:
    31 Jan 2008
    29 Aug 2009
    Link to this post
    Why does the news item class have a thumbnailurl property then?

    see:
    http://www.sitefinity.com/help/developer-manual/news-api-walkthrough.html

    Is there a way to get to the image via the news manager api then?

  4. sam
    sam avatar
    102 posts
    Registered:
    31 Jan 2008
    30 Aug 2009
    Link to this post
    reason being I am creating a jquery news rotator with images, that I will share in the code library.

    When creating a news item via the dashboard->modules->news
    you get the option to add an image with the news item...
    so I thought I shoul be able to get that info back via the api..

    Anyone done this before
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    30 Aug 2009
    Link to this post
    Hi sam,

    "Although NewsManager uses ContentManager class methods, which includes GetMetaData and SetMetaData, the News module has specific meta keys which differ from the Generic Content ones. This means that when using the two methods for meta keys, you should use the News meta keys. Here they are:"

    As you can see the article for developer manual refers to metakeys not to properties. So you can get/set Thumbnail using GetMetaData method.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. sam
    sam avatar
    102 posts
    Registered:
    31 Jan 2008
    31 Aug 2009
    Link to this post
    Ok,

    I'm using:
    content.GetMetaData("Thumbnail").ToString()

    which returns:
    [Libraries]a7782039-6c8f-45ea-ae11-0c6b832cd25b

    ImageUrl = [Libraries]a7782039-6c8f-45ea-ae11-0c6b832cd25b
    is serving a 404.


  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    31 Aug 2009
    Link to this post
    Hello sam,

    So you need to convert the guid to a url. Below is a method that you should use to resolve the [provider]Guid string.

    private string GetUrl(string value)  
        {  
            // if our value starts with ~/   
            // we return url  
            if (value.StartsWith("~/"))  
                return this.ResolveUrl(value);  
      
              
            if (value.StartsWith("["))  
            {  
                int idx = value.IndexOf("]");  
                //getting the provider [Libraries]  
                string provider = value.Substring(1, idx - 1);  
                string strId = value.Substring(idx + 1);  
                Guid id = new Guid(strId);  
      
                if (ContentManager.Providers.ContainsKey(provider))  
                {  
                    IContent cnt = ContentManager.Providers[provider].GetContent(id);  
                    if (cnt != null)  
                        return VirtualPathUtility.ToAbsolute(cnt.UrlWithExtension, this.Context.Request.ApplicationPath);  
                }  
            }  
            return value.ToString();  
        }  

    More information can be found at Chokov's Blog Post.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
7 posts, 0 answered