ICal Export

2 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" />
  2. Plamen
    Admin
    Plamen avatar
    2959 posts

    Posted 23 Apr 2012 Link to this post

    Hi Daniel,

     
    I have inspected the code that you posted by creating a test web page based on it. The export of all appointments method worked properly at my side as in our on-line demo.

    Hope this will be helpful. If you still observe the issue please let me know what else should be done in order to be able observe the issue locally.

    All the best,
    Plamen Zdravkov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top