More in this section

Forums / Developing with Sitefinity / Events Module: GetEvents() and GetCategories()

Events Module: GetEvents() and GetCategories()

2 posts, 0 answered
  1. Carl
    Carl avatar
    23 posts
    15 Jul 2008
    11 Feb 2009
    Link to this post
    I have 2 hopefully quick questions:

    #1: How do I retrieve all Event categories?
    When I try to use the EventsManager's GetCategories(), I get nothing, and CategoryCount returns 0. When initializing a new EventsManager, I'm passing in "Events", which is the same provider name that I use when retrieving all Events (below), so the provider name, I would assume, is correct.
    if (manager == null
         manager = new Telerik.Events.EventsManager("Events"); 
    int count = manager.CategoriesCount(); 
    IList cats = manager.GetCategories(); 

    #2: How do I retrieve all events between a start and end date, that belong to a specific category (or better, more than one category)?
    Is it possible to pass in a start and end date, as well as a category or list of categories? Currently I'm retrieving all of the Events between the start and end date, and then filtering that list.

    Carl J
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    11 Feb 2009
    Link to this post
    Hello Carl,

    Here is the correct example that will return all categories and count them using EventsManager.

        EventsManager eventsManager = new EventsManager("Events"); 
            IList listOfCategories = eventsManager.Content.GetCategories(); 
            int number = eventsManager.Content.CategoriesCount(); 
            if (listOfCategories.Count > 0) 
                foreach (ICategory category in listOfCategories) 
                    Response.Write(category.CategoryName + "<br />"); 

    You can filter the events that has been published with a certain category in design mode, under advanced tab of EventsView control, section Filters. You need to alter FilterExpression property.

    Here is an example ( you need to modify the Publication_Date, Expiration_Date and Category values.

    Publication_Date <= "#now" AND Expiration_Date > "#now" AND Category = "CategoryNameHere" 


            string specifiedCategory = "EventsCategory"
            string specifiedDate = "11/2/2009"
            // new instance of eventsManager 
            EventsManager eventsManager = new EventsManager("Events"); 
            //create a filer  
            List<IMetaSearchInfo> filter = new List<IMetaSearchInfo>(); 
            filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "Category", specifiedCategory, SearchCondition.Equal, JoinType.And)); 
            filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "Event_Start", specifiedDate, SearchCondition.Equal, JoinType.And)); 
            // get all events 
            IList listOfAllEvents = eventsManager.Content.GetContent(0, 0, string.Empty, nullstring.Empty, null, filter.ToArray()); 
            foreach (IContent eventItem in listOfAllEvents) 
                Response.Write(eventItem.GetMetaData("Title").ToString() + "<br />"); 

    I hope this helps.

    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
2 posts, 0 answered