ICal Export

1 posts, 0 answers
  1. Daniel
    Daniel avatar
    2 posts
    Member since:
    Apr 2012

    Posted 19 Apr 2012 Link to this post

    Hi when i try to export all my appointments as an ical file the file comes back blank, below is my code does anyone have any ideas?
    <%@ Control Language="C#" %>
    <%@ Import namespace="System" %>
    <%@ Import namespace="System.Collections.Generic" %>
    <%@ Import namespace="System.Linq" %>
    <%@ Import namespace="System.Web" %>
    <%@ Import namespace="System.Web.UI" %>
    <%@ Import namespace="System.Web.UI.WebControls" %>
    <%@ Import namespace="Telerik.Sitefinity" %>
    <%@ Import namespace="Telerik.Sitefinity.GenericContent.Model" %>
    <%@ Import namespace="Telerik.Sitefinity.Modules.Events" %>
    <%@ Import namespace="Telerik.Sitefinity.Events.Model" %>
    <%@ Import namespace="Telerik.Sitefinity.Taxonomies" %>
    <%@ Import namespace="Telerik.Sitefinity.Taxonomies.Model" %>
    <%@ Import namespace="Telerik.Sitefinity.Model" %>
     
    <script language="c#" runat="server">
     
    protected void  Page_Load(object sender, EventArgs e)
    {
        Scheduler1.ReadOnly = true;
        Scheduler1.Height = 680;
        Scheduler1.DataSource = GetSourceItems();
        Scheduler1.Width = 600;
        Scheduler1.FirstDayOfWeek = DayOfWeek.Monday;
        Scheduler1.OverflowBehavior = OverflowBehavior.Expand;
    }
     
    protected virtual IList<Event> GetSourceItems()
    {
        var list = new List<Event>();
        list = App.WorkWith().Events().Where(c => c.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).Get().ToList();
        return list;   
    }
     
    public void Scheduler1_AppointmentCreated(object sender, Telerik.Web.UI.AppointmentCreatedEventArgs e)
    {
        var EManager = EventsManager.GetManager();
        var c = (HyperLink)e.Container.FindControl("eventDetailsLink");
        var data = EManager.GetEvent(new Guid(e.Appointment.ID.ToString()));
        c.Text = data.Title;
        c.NavigateUrl = "/what's-on" + data.Urls.Where(u => u.RedirectToDefault == false).SingleOrDefault().Url;
     
        var TestID = new Guid("5A5214E8-1186-4422-AC72-B62465F6C1DB");   
        var CraftID = new Guid("90B70923-CA5B-431A-8231-AB855E50C237");
        var SummerID = new Guid("AB021AF6-D57C-45F4-A1A2-771AF0DA2BC5");
     
        if (data.GetValue<IList<Guid>>("Category").Contains(TestID))
        {
            e.Appointment.BackColor = System.Drawing.Color.Yellow;
        }
     
        if (data.GetValue<IList<Guid>>("Category").Contains(CraftID))
        {
            e.Appointment.BackColor = System.Drawing.Color.Beige;
        }
     
        if (data.GetValue<IList<Guid>>("Category").Contains(SummerID))
        {
            e.Appointment.BackColor = System.Drawing.ColorTranslator.FromHtml("#ff00ff");
        }
     
    }
     
    private void schedLoad_AppointmentCanceling(object sender, Telerik.Web.UI.AppointmentCancelingEditEventArgs e)
    {
        e.Cancel = true;
    }
     
    private void WriteCalendar(string data)
    {
     
        HttpResponse response = Page.Response;
        response.Clear();
        response.Buffer = true;
        response.ContentType = "text/calendar";
        response.ContentEncoding = Encoding.UTF8;
        response.Charset = "utf-8";
        response.AddHeader("Content-Disposition", "attachment;filename=\"RadSchedulerExport.ics\"");
        response.Write(data);
        response.End();
    }
     
    protected void Button2_Click(object sender, ImageClickEventArgs e)
    {   
        WriteCalendar(RadScheduler.ExportToICalendar(Scheduler1.Appointments));
    }
     
    </script>
     
    <telerik:RadScheduler runat="server" ID="Scheduler1"
                            SelectedView="MonthView"
                            DataKeyField = "Id"
                            DataSubjectField = "Title"
                            DataStartField = "EventStart"
                            DataEndField = "EventEnd"
                            IsReadOnly="True"
                            OnAppointmentCreated="Scheduler1_AppointmentCreated">
        <AppointmentTemplate>
            <asp:HyperLink id="eventDetailsLink" runat="server" />
        </AppointmentTemplate>
    </telerik:RadScheduler>
     
    <asp:ImageButton ID="bttn1" runat="server" ImageUrl="Export.gif" AlternateText="Export to iCalendar" onclick="Button2_Click" />

Back to Top