More in this section

Forums / Developing with Sitefinity / Import to Events

Import to Events

5 posts, 0 answered
  1. WebGeek
    WebGeek avatar
    186 posts
    20 Dec 2006
    05 Mar 2008
    Link to this post
    How would I go about importing a sql script with all of my monthly events into the event module?
  2. Ivan
    Ivan avatar
    478 posts
    16 Jun 2015
    07 Mar 2008
    Link to this post
    Hi medicalwebgeek,

    We recommend using Sitefinity API for such purposes instead of transferring data directly in the database. I've created a short sample user control here (I haven't tested it, but you'll see the idea). Just as any other part of Sitefinity, Events module has its manager class called EventsManager. You should create a new instance of it and then for each event in your old database, create new content (yes content, namely Events module is based on GC module just as News or Blogs). Before you save that new event, you should set the meta data appropriately and that's it. Let me know if you have any problems.

    using System; 
    using System.Collections; 
    using System.Configuration; 
    using System.Data; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.HtmlControls; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using Telerik.Events; 
    using Telerik.Cms.Engine; 
    public partial class test_test : System.Web.UI.UserControl 
        protected void Page_Load(object sender, EventArgs e) 
            EventsManager eventsManager = new EventsManager(); 
            // generall you would pull a dataset or something like that 
            // here and iterate through all events in your dataset or list 
            // and for each of them add a new event through EventsManager class 
            // and then for each row/record you  
            int numberOfEventsToImport = 30; 
            for(int i = 0; i < numberOfEventsToImport; i++) 
                // replace the hard coded values with the ones from your database 
                string title = "title"
                string street = "street"
                string city = "city"
                string country = "country"
                string state = "state"
                string eventStart = DateTime.Now.ToString(); 
                string eventEnd = DateTime.Now.AddHours(1).ToString(); 
                string publicationDate = DateTime.Now.ToString(); 
                string expirationDate = DateTime.MaxValue; 
                string contactName = "contact name"
                string contactEmail = "contact email"
                string contactPhone = "contact phone"
                string contactCell = "contact cell"
                string contactWeb = "contact web"
                string categoryName = "category"
                // if you are storing categories as well, then you should 
                // add categories here as well 
                ICategory category = eventsManager.GetCategory(categoryName); 
                if (category == null
                    category = eventsManager.CreateCategory(categoryName); 
                // create new content and set meta data, then save the content 
                IContent newEvent = eventsManager.CreateContent(); 
                newEvent.DateCreated = DateTime.Now; 
                newEvent.SetMetaData("Title", title); 
                newEvent.SetMetaData("Street", street); 
                newEvent.SetMetaData("City", city); 
                newEvent.SetMetaData("State", state); 
                newEvent.SetMetaData("Event_Start", eventStart); 
                newEvent.SetMetaData("Event_End", eventEnd); 
                newEvent.SetMetaData("Publication_Date", publicationDate); 
                newEvent.SetMetaData("Expiration_Date", expirationDate); 
                newEvent.SetMetaData("Contact_Name", contactName); 
                newEvent.SetMetaData("Contact_Email", contactEmail); 
                newEvent.SetMetaData("Contact_Phone", contactPhone); 
                newEvent.SetMetaData("Contact_Cell", contactCell); 
                newEvent.SetMetaData("Contact_Web", contactWeb); 
                newEvent.SetMetaData("Category", categoryName); 

    All the best,
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Joe
    Joe avatar
    64 posts
    05 Jul 2012
    15 Apr 2008
    Link to this post
    Do you have a sample for SiteFinity 3.2?  The above example does not work.  In fact, it seems that some of the methods have changed.  Here is what I was able to get so far.  It successfully created a Generic Content item but it has no title, no content and is not recognized as an Event.

            string eventTitle = "Tech Lunch South"
            string contactName = "Joseph Guadagno"
            string contactEmail = ""
            string contactPhone = ""
            string contactCell = ""
            string contactWeb = ""
            string street = "Chandler Fashion Center"
            string city = "Chandler"
            string state = "AZ"
            DateTime eventStartDate = DateTime.Parse("04/16/2008 11:00 AM"); 
            DateTime eventEndDate = DateTime.MaxValue; 
            DateTime eventExpirationDate = DateTime.MaxValue; 
            string categoryName = "Tech Lunch South"
            // Different then the example 
            EventsManager eventsManager = new Telerik.Events.EventsManager("Events"); 
            ICategory category = eventsManager.GetCategory(categoryName); 
            if (category == null
                category = eventsManager.CreateCategory(categoryName); 
                eventEndDate = eventStartDate.AddHours(2); 
                eventExpirationDate = eventEndDate; 
                // Different from the Example 
                IContent newEvent = eventsManager.CreateContent("text/html", Guid.NewGuid()); 
                newEvent.SetMetaData("Title", eventTitle); 
                newEvent.SetMetaData("Street", street); 
                newEvent.SetMetaData("City", city); 
                newEvent.SetMetaData("State", state); 
                newEvent.SetMetaData("Contact_Name", contactName); 
                newEvent.SetMetaData("Contact_Email", contactEmail); 
                newEvent.SetMetaData("Contact_Phone", contactPhone); 
                newEvent.SetMetaData("Contact_Cell", contactCell); 
                newEvent.SetMetaData("Contact_Web", contactWeb); 
                newEvent.SetMetaData("Event_Start", eventStartDate.ToString()); 
                newEvent.SetMetaData("Event_End", eventEndDate.ToString()); 
                newEvent.SetMetaData("Publication_Date", DateTime.Now.ToString()); 
                newEvent.SetMetaData("Expiration_Date", eventExpirationDate.ToString()); 
                newEvent.SetMetaData("Category", categoryName); 
                // Creates the Generic content 
                // Move to the next week 
                eventStartDate = eventStartDate.AddDays(7); 
                if (eventStartDate.Year== 2009) break
            } while (true); 

  4. Ivan
    Ivan avatar
    478 posts
    16 Jun 2015
    16 Apr 2008
    Link to this post
    Hi Joseph,

    First of all, I deeply apologize for the sloppiness I have demonstrated with my example and regret that my actions wasted your time and caused you frustrations. I wanted to reply as soon as possible (back then) and therefore had not tested the code... it was with good intention, but as they say road to hell is paved with good intentions.

    I have modified the code and tested it this time, so I am posting it again:

    1 using System;  
    2 using System.Collections;  
    3 using System.Configuration;  
    4 using System.Data;  
    5 using System.Web;  
    6 using System.Web.Security;  
    7 using System.Web.UI;  
    8 using System.Web.UI.HtmlControls;  
    9 using System.Web.UI.WebControls;  
    10 using System.Web.UI.WebControls.WebParts;  
    12 using Telerik.Events;  
    13 using Telerik.Cms.Engine;    
    15 public partial class EventsAPI_AddEventControl : System.Web.UI.UserControl  
    16 {  
    17     protected void Page_Load(object sender, EventArgs e)  
    18     {  
    19         EventsManager eventsManager = new EventsManager("Events");  
    21         // generall you would pull a dataset or something like that    
    22         // here and iterate through all events in your dataset or list    
    23         // and for each of them add a new event through EventsManager class    
    25         // and then for each row/record you     
    26         int numberOfEventsToImport = 30;  
    28         for (int i = 0; i < numberOfEventsToImport; i++)  
    29         {  
    30             // replace the hard coded values with the ones from your database    
    31             string title = "title";  
    32             string street = "street";  
    33             string city = "city";  
    34             string country = "country";  
    35             string state = "state";  
    36             DateTime eventStart = DateTime.Now;  
    37             DateTime eventEnd = DateTime.Now.AddHours(1);  
    38             DateTime publicationDate = DateTime.Now;  
    39             DateTime expirationDate = DateTime.MaxValue;  
    40             string contactName = "contact name";  
    41             string contactEmail = "contact email";  
    42             string contactPhone = "contact phone";  
    43             string contactCell = "contact cell";  
    44             string contactWeb = "contact web";  
    45             string categoryName = "category";  
    47             // if you are storing categories as well, then you should    
    48             // add categories here as well    
    49             ICategory category = eventsManager.Content.GetCategory(categoryName);  
    50             if (category == null)  
    51             {  
    52                 category = eventsManager.Content.CreateCategory(categoryName);  
    53                 eventsManager.Content.SaveCategory(category);  
    54             }  
    56             // create new content and set meta data, then save the content    
    57             IContent newEvent = eventsManager.Content.CreateContent("text/html");  
    58             newEvent.SetMetaData("Title", title);  
    59             newEvent.SetMetaData("Street", street);  
    60             newEvent.SetMetaData("City", city);  
    61             newEvent.SetMetaData("State", state);  
    62             newEvent.SetMetaData("Event_Start", eventStart);  
    63             newEvent.SetMetaData("Event_End", eventEnd);  
    64             newEvent.SetMetaData("Publication_Date", publicationDate);  
    65             newEvent.SetMetaData("Expiration_Date", expirationDate);  
    66             newEvent.SetMetaData("Contact_Name", contactName);  
    67             newEvent.SetMetaData("Contact_Email", contactEmail);  
    68             newEvent.SetMetaData("Contact_Phone", contactPhone);  
    69             newEvent.SetMetaData("Contact_Cell", contactCell);  
    70             newEvent.SetMetaData("Contact_Web", contactWeb);  
    71             newEvent.SetMetaData("Category", categoryName);  
    72             eventsManager.Content.SaveContent(newEvent);  
    73         }    
    76     }  

    To clarify why the first example didn't work, I'll outline the mistakes I've made:

    • Since Events module is based on Generic Content module, in order to work with the proper generic content provider, GC methods should be used through Content property, not directly through the manager. So for example: instead of eventsManager.SaveContent(newEvent) it should be eventsManager.Content.SaveContent(newEvent).
    • DateTimes declared as strings
    • EventsManager needs to be instatiated with provider name, there is no empty constructor

    Once again, my deepest apologies.

    Sincerely yours,
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Joe
    Joe avatar
    64 posts
    05 Jul 2012
    16 Apr 2008
    Link to this post
    This works... Thanks!
Register for webinar
5 posts, 0 answered