使用Exchange EWS API显示日历
本文关键字:显示 日历 API EWS Exchange 使用 | 更新日期: 2023-09-27 18:11:20
在我的项目中,我使用MVC, c#, razor…
我成功地使用EWS在我的日历上创建约会。但是,我不知道如何使用EWS显示日历。
对于我收集到的,我需要在EWS上执行GETAppointments,然后使用其他一些块来显示使用从GET获得的那些约会的日历。
我在网上搜索,发现了一个叫daypilot(asp.net)的金块,但是我似乎不能适应我的项目,也找不到任何替代品。
真的找不到任何关于这个问题的好的教程,或者也许我只是在寻找错误的主题…
有任何想法,或链接到好的教程?
对于将来可能遇到同样问题的任何人,我将发布我解决方案的某些部分的副本:
webservice I created:
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;
}
Then on controller:
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);
}
最后是View:
<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/)。