3
Answers

Loading Events from Exchange Server

Hazel Mahmud

Hazel Mahmud

8y
425
1
Hello..
 
 i have below code to load event from exchange server  to asp .net c# page. unfortunately, i get this error:
 
(Microsoft.Exchange.WebServices.Data.ServiceXmlDeserializationException: The expected XML node type was XmlDeclaration, but the actual type is Element.)
 
error is at this line : 
FindFoldersResults findFolderResults = Service.FindFolders(WellKnownFolderName.Root, sfSearchFilter, view);
can anyone help me with this error. below are the codes :
 
protected void Page_Load(object sender, EventArgs e)
{
LoadAppointments();
}

private ExchangeService Service
{
get
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials("[email protected]", "dalia2003", "uum.edu.my");
// service.Url = new Uri("https://outlook.office365.com/ews/exchange.asmx");
service.Url = new Uri("https://uummail2.uum.edu.my/owa/#path=/mail");
return service;
}
}

private CalendarFolder FindDefaultCalendarFolder()
{
return CalendarFolder.Bind(Service, WellKnownFolderName.Calendar, new PropertySet());
}


private CalendarFolder FindNamedCalendarFolder(string name)
{
FolderView view = new FolderView(100);
view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
view.PropertySet.Add(FolderSchema.DisplayName);
view.Traversal = FolderTraversal.Deep;

SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(FolderSchema.FolderClass, "IPF.Appointment");

FindFoldersResults findFolderResults = Service.FindFolders(WellKnownFolderName.Root, sfSearchFilter, view);
return findFolderResults.Where(f => f.DisplayName == name).Cast<CalendarFolder>().FirstOrDefault();
}

private void LoadAppointments()
{
DateTime startDate = DayPilot.Utils.Week.FirstDayOfWeek();
DateTime endDate = startDate.AddDays(7);

CalendarFolder calendar = FindNamedCalendarFolder("Calendar"); // or FindDefaultCalendarFolder()

CalendarView cView = new CalendarView(startDate, endDate, 50);
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Id);
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);

DayPilotCalendar1.ViewType = ViewTypeEnum.Week;
DayPilotCalendar1.DataStartField = "Start";
DayPilotCalendar1.DataEndField = "End";
DayPilotCalendar1.DataIdField = "Id";
DayPilotCalendar1.DataTextField = "Subject";

DayPilotCalendar1.DataSource = appointments;
DayPilotCalendar1.DataBind();

DayPilotCalendar1.Update();

 
 
Answers (3)