static void MyTest() { // IMPORTANT: ExchangeService is NOT thread safe, so one should create an instance of // ExchangeService whenever one needs it. ExchangeService myService = new ExchangeService(ExchangeVersion.Exchange2007_SP1); myService.Credentials = new NetworkCredential("*****@*****.**", "myPassword00"); myService.Url = new Uri("http://mailwebsvc-t.services.local/ews/exchange.asmx"); // next line is very practical during development phase or for debugging myService.TraceEnabled = true; Folder myPublicFoldersRoot = Folder.Bind(myService, WellKnownFolderName.PublicFoldersRoot); string myPublicFolderPath = @"OK soft GmbH (DE)\Gruppenpostfächer\_Template - Gruppenpostfach\_Template - Kalender"; string[] folderPath = myPublicFolderPath.Split('\\'); FolderId fId = myPublicFoldersRoot.Id; foreach (string subFolderName in folderPath) { fId = FindPublicFolder(myService, fId, subFolderName); if (fId == null) { Console.WriteLine("ERROR: Can't find public folder {0}", myPublicFolderPath); return; } } // verify that we found Folder folderFound = Folder.Bind(myService, fId); if (String.Compare(folderFound.FolderClass, "IPF.Appointment", StringComparison.Ordinal) != 0) { Console.WriteLine("ERROR: Public folder {0} is not a Calendar", myPublicFolderPath); return; } CalendarFolder myPublicFolder = CalendarFolder.Bind(myService, //WellKnownFolderName.Calendar, fId, PropertySet.FirstClassProperties); if (myPublicFolder.TotalCount == 0) { Console.WriteLine("Warning: Public folder {0} has no appointment. We try to create one.", myPublicFolderPath); Appointment app = new Appointment(myService); app.Subject = "Writing a code example"; app.Start = new DateTime(2010, 9, 9); app.End = new DateTime(2010, 9, 10); app.RequiredAttendees.Add("*****@*****.**"); app.Culture = "de-DE"; app.Save(myPublicFolder.Id, SendInvitationsMode.SendToNone); } // We will search using paging. We will use page size 10 ItemView viewCalendar = new ItemView(10); // we can include all properties which we need in the view // If we comment the next line then ALL properties will be // read from the server. We can see there in the debug output viewCalendar.PropertySet = new PropertySet(ItemSchema.Subject); viewCalendar.Offset = 0; viewCalendar.OffsetBasePoint = OffsetBasePoint.Beginning; viewCalendar.OrderBy.Add(ContactSchema.DateTimeCreated, SortDirection.Descending); FindItemsResults <Item> findResultsCalendar; do { findResultsCalendar = myPublicFolder.FindItems(viewCalendar); foreach (Item item in findResultsCalendar) { if (item is Appointment) { Appointment appoint = item as Appointment; Console.WriteLine("Subject: \"{0}\"", appoint.Subject); } } if (findResultsCalendar.NextPageOffset.HasValue) { // go to the next page viewCalendar.Offset = findResultsCalendar.NextPageOffset.Value; } }while (findResultsCalendar.MoreAvailable); }
public AppointmentObjectId GetParentAppointment(AppointmentObjectId dependentAppointment, IList <PropertyDefinitionBase> filterPropertySet) { IList <PropertyDefinitionBase> findPropertyCollection = new List <PropertyDefinitionBase>() { ItemSchema.DateTimeReceived, ItemSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.IsAllDayEvent, AppointmentSchema.IsRecurring, AppointmentSchema.IsCancelled, AppointmentSchema.TimeZone }; var icalId = dependentAppointment.ICalUid; var mailboxId = dependentAppointment.Organizer.Address; var objectId = new AppointmentObjectId() { ICalUid = dependentAppointment.ICalUid, Organizer = dependentAppointment.Organizer }; try { // Initialize the calendar folder via Impersonation SetImpersonation(ConnectingIdType.SmtpAddress, mailboxId); CalendarFolder AtndCalendar = CalendarFolder.Bind(ExchangeService, new FolderId(WellKnownFolderName.Calendar, mailboxId), new PropertySet()); SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(CleanGlobalObjectId, dependentAppointment.Base64UniqueId); ItemView ivItemView = new ItemView(5) { PropertySet = new PropertySet(BasePropertySet.IdOnly, findPropertyCollection) }; FindItemsResults <Item> fiResults = AtndCalendar.FindItems(sfSearchFilter, ivItemView); if (fiResults.Items.Count > 0) { var objectItem = fiResults.Items.FirstOrDefault(); var ownerAppointmentTime = (Appointment)Item.Bind(ExchangeService, objectItem.Id, new PropertySet(filterPropertySet)); Trace.WriteLine($"The first {fiResults.Items.Count()} appointments on your calendar from {ownerAppointmentTime.Start.ToShortDateString()} to {ownerAppointmentTime.End.ToShortDateString()}"); objectId.Item = ownerAppointmentTime; objectId.Id = ownerAppointmentTime.Id; var props = ownerAppointmentTime.ExtendedProperties.Where(p => (p.PropertyDefinition.PropertySet == DefaultExtendedPropertySet.Meeting)); if (props.Any()) { objectId.ReferenceId = (string)props.First(p => p.PropertyDefinition.Name == EWSConstants.RefIdPropertyName).Value; objectId.MeetingKey = (int)props.First(p => p.PropertyDefinition.Name == EWSConstants.MeetingKeyPropertyName).Value; } } } catch (Exception ex) { Trace.WriteLine($"Error retreiving calendar {mailboxId} msg:{ex.Message}"); } return(objectId); }