使用Exchange EWS API显示日历

时间:2016-10-04 09:39:39

标签: c# asp.net-mvc razor

在我的项目中,我正在使用MVC,C#,razor ......

我成功使用EWS在我的日历上创建约会。 但是我不知道如何使用EWS显示日历。

对于我收集的内容,我需要在EWS上进行GETAppointments,之后使用其他一些金块来显示使用我从GET获得的约会的日历。

我在网上搜索并发现了一个名为daypilot(asp.net)的金块,然而我似乎无法使其适应我的项目而无法找到任何替代方案。

真的找不到任何关于此事的好教程,或者我只是在寻找错误的主题......

任何想法或指向优秀教程的链接?

提前致谢。

1 个答案:

答案 0 :(得分:0)

对于将来可能遇到同样问题的人,我会发布我的解决方案的某些部分的副本:

我创建了webservice:

    public IEnumerable<Microsoft.Exchange.WebServices.Data.Appointment> getAppointments(string userName, string userPwd)
    {

        DateTime startDate = DateTime.Now.AddYears(-1);
        DateTime endDate = startDate.AddYears(1);
        const int NUM_APPTS = 5;

        ExchangeService serviceExchange = ExchangeWebService.ConnectToService(userName, userPwd);


        // Initialize the calendar folder object with only the folder ID. 
        CalendarFolder calendar = CalendarFolder.Bind(serviceExchange, WellKnownFolderName.Calendar, new PropertySet());

        // Set the start and end time and number of appointments to retrieve.
        CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);

        // Limit the properties returned to the appointment's subject, start time, and end time.
        cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);

        // Retrieve a collection of appointments by using the calendar view.
        FindItemsResults<Microsoft.Exchange.WebServices.Data.Appointment> appointments = calendar.FindAppointments(cView);


        return appointments;
    }

然后在控制器上:

    public JsonResult AllCalendarApp()
    {
        WebServiceBO webServiceBO = new WebServiceBO();
        var CalendarAppointments = webServiceBO.getAppointments(User.Identity.Name, this.Session["UserPass"].ToString());

        List<string> listAllAppontments = new List<string>();

        List<calendario> listAllAppontmentss = new List<calendario>();
        foreach (Microsoft.Exchange.WebServices.Data.Appointment item in CalendarAppointments)
        {
            listAllAppontmentss.Add(new calendario() { title = item.Subject, start = item.Start });
        }

        return Json(listAllAppontmentss, JsonRequestBehavior.AllowGet);
    }

最后在视图上:

        <div id='calendar'></div>

$(document).ready(function () {

    $.ajax({
        url: '/BackOffice/AllCalendarApp',
        type: 'POST',
        data: {},
        success: function (data) {
            $('#calendar').fullCalendar({
                editable: false,

                events: data
                });
        }
    })


});

我使用fullcalender来显示日历(https://fullcalendar.io/)。