Sitefinity ASP.NET CMS - Content Management System

KB Article

Home >  Support >  Knowledge Base >  KB Article
How to display news published within the last month - ID#1072
Rating: Not rated
Last Modified: 8/5/2008
Related categories: Workarounds;

Article information

Article relates to

 Sitefinity SP2 Hotfix 1616

Created by

 Penka Ivanova    

Last modified by

 Rebecca


You need to create a custom control that inherits the base NewsView class and override the CreateFilter method:

using System; 
using System.Data; 
using System.Configuration; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using Telerik.News.WebControls; 
using Telerik.Cms.Engine; 
using System.Collections.Generic; 
 
/// <summary> 
/// Summary description for LatestNews 
/// </summary> 
namespace Telerik.News.WebControls 
    public class LatestNews : NewsView 
    { 
        //Overwrite CreateFilter function so that we can apply our custom filter 
        protected override IMetaSearchInfo[] CreateFilter() 
        { 
            IMetaSearchInfo[] defaultContentViewFilter = base.CreateFilter(); 
            List<IMetaSearchInfo> newFilter = new List<IMetaSearchInfo>(defaultContentViewFilter); 
 
            DateTime date = DateTime.Now.AddMonths(-1); 
            MetaSearchInfo filter = new MetaSearchInfo(MetaValueTypes.DateTime, "Publication_Date", date, SearchCondition.GreaterOrEqual); 
            newFilter.Add(filter); 
 
            return newFilter.ToArray(); ; 
        } 
    } 
 

You should then register the LatestNews control in the <toolboxControls> section of the application web.config in order to display it in the Add Controls toolbox:

<add name="Latest News" section="News" type="Telerik.News.WebControls.LatestNews, App_Code"/>  
 

Article Files

  • LatestNews.zip



  • Article Comments

    There are no comments yet.
    Please Sign In to rate this article or to add it to your favorites.