iCalendar Export

This example demonstrates the Bootstrap Scheduler's support for the iCalendar data exchange format. It facilitates data transfer between applications that use Scheduler and other applications, such as Apple iCal, Google Calendar, Microsoft Exchange Server, Microsoft Office Outlook 2007, Novell GroupWise, Windows Calendar.

In this demo, you can save appointments into an iCalendar file with the .ics extension on the client host. This example creates an iCalendarExporter class instance and calls its Export method to save data to a memory stream. Then it is written to an output stream of an HttpResponse object.

<dx:BootstrapButton ID="ButtonExport" runat="server" Text="Export appointments" ClientInstanceName="buttonExport"
    AutoPostBack="true" OnClick="ButtonExport_Click">
</dx:BootstrapButton>
<dx:BootstrapScheduler ID="SchedulerExport" runat="server" ActiveViewType="WorkWeek" ClientInstanceName="schedulerExport"
    OnPopupMenuShowing="SchedulerExport_PopupMenuShowing">
    <Views>
        <DayView DayCount="2" ScrollAreaHeight="400">
        </DayView>
        <WorkWeekView ScrollAreaHeight="400">
        </WorkWeekView>
        <WeekView Enabled="false"></WeekView>
        <TimelineView Enabled="false"></TimelineView>
    </Views>
</dx:BootstrapScheduler>
protected void ButtonExport_Click(object sender, EventArgs e) {
    iCalendarExporter exporter = SchedulerExport.SelectedAppointments.Count > 0 ?
        new iCalendarExporter(SchedulerExport.Storage, SchedulerExport.SelectedAppointments) :
        new iCalendarExporter(SchedulerExport.Storage);
    PostCalendarFile(exporter);
}
protected void SchedulerExport_PopupMenuShowing(object sender, BootstrapSchedulerPopupMenuShowingEventArgs e) {
    BootstrapSchedulerPopupMenu menu = e.Menu;
    if (menu.MenuId.Equals(SchedulerMenuItemId.AppointmentMenu)) {
        DevExpress.Web.MenuItem item = new BootstrapMenuItem("Export Appointment", "ExportAppointment");
        menu.Items.Insert(1, item);
        menu.ClientSideEvents.ItemClick = "function(s, e) { OnMenuClick(s,e); }";
    }
}
void PostCalendarFile(iCalendarExporter exporter) {
    using(MemoryStream memoryStream = new MemoryStream()) {
        exporter.Export(memoryStream);
        Stream outputStream = Response.OutputStream;
        memoryStream.WriteTo(outputStream);
        outputStream.Flush();
    }
    Response.ContentType = "text/calendar";
    Response.AddHeader("Content-Disposition", "attachment; filename=appointments.ics");
    Response.End();
}
function OnMenuClick(s, e) {
    if(e.item.GetItemCount() <= 0) {
        if(e.item.name == "ExportAppointment")
            buttonExport.DoClick();
        else
            schedulerExport.RaiseCallback("MNUAPT|" + e.item.name);
    }
}

iCalendar Import

This example demonstrates the Bootstrap Scheduler's support for the iCalendar data exchange format. It facilitates data transfer between applications that use Scheduler and other applications, such as Apple iCal, Google Calendar, Microsoft Exchange Server, Microsoft Office Outlook 2007, Novell GroupWise, Windows Calendar.

In this demo, you can load appointments from the iCalendar file. This example loads file data into a memory stream, creates an iCalendarImporter class instance and calls its Import method to load data into a scheduler. You can check the corresponding box to clear scheduler appointments before import.

<dx:BootstrapUploadControl ID="UploadControlImport" ClientInstanceName="uploadControlImport" runat="server"
    OnFileUploadComplete="UploadControlImport_FileUploadComplete">
    <ValidationSettings MaxFileSize="1048576" />
    <ClientSideEvents TextChanged="function(s, e) { UploadControlImport_TextChanged(); }"
        FilesUploadComplete="function(s, e) { UploadControlImport_FileUploadComplete(); }"
        FilesUploadStart="function(s, e) { UploadControlImport_FileUploadStart(); }" />
</dx:BootstrapUploadControl>
<dx:BootstrapScheduler ID="SchedulerImport" ClientInstanceName="schedulerImport" runat="server" ActiveViewType="WorkWeek"
    OnCustomCallback="SchedulerImport_CustomCallback">
    <Views>
        <DayView DayCount="2" ScrollAreaHeight="400">
        </DayView>
        <WorkWeekView ScrollAreaHeight="400">
        </WorkWeekView>
        <WeekView Enabled="false"></WeekView>
        <TimelineView Enabled="false"></TimelineView>
    </Views>
</dx:BootstrapScheduler>
protected void UploadControlImport_FileUploadComplete(object sender, DevExpress.Web.FileUploadCompleteEventArgs e) {
    var uploadControl = (BootstrapUploadControl)sender;
    var uploadedFile = uploadControl.UploadedFiles[0];
    if(!IsFileNameCorrect(uploadedFile.FileName)) {
        e.IsValid = false;
        e.ErrorText = "Incorrect file type";
    }
    else if(uploadedFile.IsValid)
        Session["UploadedFile"] = GetBytes(uploadedFile.FileContent);
}
protected void SchedulerImport_CustomCallback(object sender, DevExpress.Web.CallbackEventArgsBase e) {
    if(e.Parameter != "IMPRTAPT")
        return;
    using(Stream stream = GetStream()) {
        if(stream == null)
            return;
        SchedulerImport.Storage.Appointments.Clear();
        iCalendarImporter importer = new iCalendarImporter(SchedulerImport.Storage);
        importer.Import(stream);
        Session["UploadedFile"] = null;
    }
}
Stream GetStream() {
    byte[] buf = Session["UploadedFile"] as byte[];
    if(buf == null)
        return null;
    Stream stream = new MemoryStream(buf);
    return stream;
}
bool IsFileNameCorrect(string fileName) {
    int length = fileName.Length;
    return fileName.Substring(length - 4, 4) == ".ics";
}
byte[] GetBytes(Stream stream) {
    stream.Position = 0;
    byte[] buf = new byte[stream.Length];
    stream.Read(buf, 0, (int)stream.Length);
    return buf;
}
function UploadControlImport_TextChanged() {
    uploadControlImport.UploadFile();
}
function UploadControlImport_FileUploadStart() {
    schedulerImport.ShowLoadingPanel();
}
function UploadControlImport_FileUploadComplete() {
    schedulerImport.HideLoadingPanel();
    schedulerImport.PerformCallback("IMPRTAPT");
}
Screen Size
Color Themes
Demo QR Code