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

Forums / Developing with Sitefinity / Lost in the API

Lost in the API

12 posts, 0 answered
  1. Matt
    Matt avatar
    17 posts
    Registered:
    03 Jan 2008
    07 Jul 2008
    Link to this post

        Hello all.  I'm trying to access some Events data through the API.  From what little I can gather from the documentation I know that I'll need to instanciate a ContentManager with the string "Events" as the constructer arg, but after that I'm rather lost at retrieving the various parts (like the title for instance) of the Event from the resulting manager object, or the collection that manager.GetContent() provides me.  It seems like manager.MetaKeys has a lot of useful information in it, but I'm not sure how to use that to get the values of the various fields.

    I was just wondering if there was some sort of "map" of where the data goes when you create an Event via the Events module.  In the absense of a map, is there an example of how to retrieve the event title via the API?

    Thanks in advance for your help on this!

  2. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    08 Jul 2008
    Link to this post
    Hi Matt,

    We are sorry that you are confused by our API, but we understand it. Namely, we were not able to publish the Events API walkthrough in the new developer's manual, but the topic has been scheduled for release this Friday (here is the blog post: http://blogs.sitefinity.com/Ivan/Post/08-07-07/developer_manual_scheduled_topics_for_july_11th_2008.aspx ). The topic will explain the major interfaces in the Events module, as well as give examples on how to work with Events module API.

    In the meantime, here is how you can get a list of events and write out their titles:

    Telerik.Events.EventsManager manager = new Telerik.Events.EventsManager(Telerik.Events.EventsManager.DefaultProviderName);  
     
    IList allEvents = manager.Content.GetContent();  
     
    foreach(Telerik.Cms.Engine.IContent cnt in allEvents)  
    {  
        // the list of meta data for any module can be found in web.config  
        // in metaFields section  
        HttpContext.Current.Response.Write(cnt.GetMetaData("Title"));  

    The Events module itself has two ways of searching for events, depending on whether you are searching by meta data or by Event Start and End date. More about all of this, we will provide in Developers Manual this week. Hope it will not be too much of a wait for you.

    I hope you'll find this information helpful. Let us know if there is anything else we can do for you.

    Regards,
    Ivan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Matt
    Matt avatar
    17 posts
    Registered:
    03 Jan 2008
    08 Jul 2008
    Link to this post
    Ah, the web.config, that listing is the step I was missing, thanks!
  4. Klemen Slavič
    Klemen Slavič avatar
    30 posts
    Registered:
    24 Jul 2009
    12 Nov 2010
    Link to this post
    I, too, am having problems handling the Events module API, specifically, dealing with creating events.

    So far, I've managed to create an IContent object via the EventsManager instance, but the content that I save back into the EventsManager instance gets translated into generic content:

    var newContent = eventsManager.CreateContent("text/html");
     
    newContent.SetMetaData("Events.Title", EventName.Text);
    newContent.SetMetaData(eventsManager.EventStartField, (DateTime)EventStartTime.SelectedDate);
    newContent.SetMetaData(eventsManager.EventEndField, (DateTime)EventEndTime.SelectedDate);
    newContent.SetMetaData(eventsManager.StreetField, EventStreet.Text);
    newContent.SetMetaData(eventsManager.CityField, EventCity.Text);
    newContent.SetMetaData(eventsManager.CountryField, "Slovenia");
    newContent.Content = EventDescription.Text;
    newContent.Language = Page.UICulture;
     
    eventsManager.SaveContent(newContent);

    By running this code, I end up with a generic content item inside the Generic Content Module with no title and only a description, while I expect it to be entered into the Events item list.

    What am I doing wrong?

    Also, is there any documentation on how to deal with the Modules API? The docs themselves don't offer any code examples beyond the Generic Content Module.
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Nov 2010
    Link to this post
    Hello Klemen ,

    1. Make sure that you use "Events" manager as a provider - EventsManager("Events")
    2. You can use ContentManager("Events")

    You can take a look at


    Events is a Generic Content based module and it reuses the logic from Generic Content - .NET Inheritance.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Klemen Slavič
    Klemen Slavič avatar
    30 posts
    Registered:
    24 Jul 2009
    12 Nov 2010
    Link to this post
    I already am using the "Events" provider, via the ProviderName public property on the control:

    protected EventsManager eventsManager;
    protected string providerName;
     
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        if (String.IsNullOrEmpty(providerName)) {
            providerName = "Events";
        }
     
        if (!String.IsNullOrEmpty(providerName)) {
            if (eventsManager == null || eventsManager.Provider.Name != ProviderName)
                eventsManager = new EventsManager(ProviderName);
        }
    }
     
     
     
    [Category("Data")]
    public string ProviderName
    {
        get
        {
            if (String.IsNullOrEmpty(providerName)) {
                providerName = "Events";
            }
            return providerName;
        }
        set
        {
            providerName = value;
        }
    }

    That way I know I'm using the correct provider name and can configure it when I need it inside the CMS. The code in OnInit is something I adapted from this thread.

    Unfortunately, this results in the situation I explained previously.
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Nov 2010
    Link to this post
    Hello Klemen,

    Somewhere in your code you  are reverting back to the default provider of Generic Content. Also in AppointmentInsert create an instance of the EventsManager and then create the content item

    void EventsSchedule_AppointmentInsert(object sender, SchedulerCancelEventArgs e)
    {
        var eventsManager = new EventsManager("Events");
        IContent newEvent = eventsManager.Content.CreateContent("text/html");
        newEvent.Content = e.Appointment.Subject;
        newEvent.SetMetaData("Title", e.Appointment.Subject);
        newEvent.SetMetaData("Event_Start", e.Appointment.Start);
        newEvent.SetMetaData("Event_End", e.Appointment.End);
        eventsManager.Content.SaveContent(newEvent, ContentStatus.Published);
    }


    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Klemen Slavič
    Klemen Slavič avatar
    30 posts
    Registered:
    24 Jul 2009
    12 Nov 2010
    Link to this post
    Thanks for the correction, but it seems I'm still missing something in that code:

    eventsManager = new EventsManager("Events");

    var newContent = eventsManager.Content.CreateContent("text/html");
    newContent.SetMetaData("Title", EventName.Text);
    newContent.SetMetaData("Event_Start", (DateTime)EventStartTime.SelectedDate);
    newContent.SetMetaData("Event_End", (DateTime)EventEndTime.SelectedDate);
    newContent.SetMetaData("Street", EventStreet.Text);
    newContent.SetMetaData("City", EventCity.Text);
    newContent.SetMetaData("Country", "SLOVENIA");
    newContent.SetMetaData("PublicationDate", DateTime.Now);
    newContent.Content = EventDescription.Text;
    newContent.Language = Page.UICulture;
    newContent.Status = Telerik.Cms.Engine.ContentStatus.Published;

    eventsManager.Content.SaveContent(newContent);

    This code does save the event item inside the Events item list in the CMS, but the event is not listed on the page itself until I click Edit and Save inside the Events Module editor in the CMS.

    Just to be clear: I'm using a custom form (not the Scheduler control in the previously mentioned thread) inside a user control with enabled localization.
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Nov 2010
    Link to this post
    Hello Klemen,

    1.If you have localization enabled make sure that you create the content item in the correct CurrentUICulture.
    2. Check whether the content is marked as published( if you have workflow enabled the content cannot be published directly).



    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Klemen Slavič
    Klemen Slavič avatar
    30 posts
    Registered:
    24 Jul 2009
    12 Nov 2010
    Link to this post
    The page is set to the Page.UICulture, as is stated in the above code example. Should I be using a different property? Also, I'm setting the newContent.Status property to Telerik.Cms.Engine.ContentStatus.Published and can verify that the event has a published status in the CMS after sumbitting the form.

    Where can I set/verify the workflow setting related to publishing? I'm using default settings, as far as I know.
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Nov 2010
    Link to this post
    Hello Klemen,

    You have to use CurrentUICulture that have to be set for the current thread. Workflow is enabled/disabled through <cmsEngine> node

    <add name="Events" allowLocalization="True" allowWorkflow="True"....


    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. Klemen Slavič
    Klemen Slavič avatar
    30 posts
    Registered:
    24 Jul 2009
    15 Nov 2010
    Link to this post
    I've solved the problem; the Events item requires Publication_Date and Expiration_Date to be set on the item before it's displayed on the site.

    Thanks.
Register for webinar
12 posts, 0 answered