Hello,
I want to copy some specific appointments form one Users calender to other user calendars over the ews managed api 2.0.
The appointments to be copied, have a specific Subject (e.g. "Infomeeting" and "Sommerfest").
I have managed to fetch the appointments from the reference calendar (lets say from User1) and I am trying to save/copy them to the user calendars, who are members of a distribution group (e.g. distibutiongroup1). User1 is also a member of the Distributiongroup1.
I have also managed to bind and search every user calendar of the Distribution1, if the appointment is already existing.
My problem is on how to save it in the Distributiongroup1 mebers calendars.
Hier is my code:
namespace Einlesen_und_Schreiben { class Program { static void Main(string[] args) { //Instantiate the ExchangeService class+ Exchange Certificate Validation + Imparsonate ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack; ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2); service.Credentials = new NetworkCredential("kalenderuser", "password", "ws"); service.AutodiscoverUrl("kalenderuser@email", RedirectionUrlValidationCallback); //Impersonate reference User-Calendar string impersonatedUser = "User1@email"; service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, impersonatedUser); //Determine Appointment Subject string subjectInfomeeting = "Infomeeting"; string subjectSommerfest = "Sommerfest"; //Search and find the appointment CalendarView userCalendar = new CalendarView(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(7)); userCalendar.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties); FindItemsResults<Appointment> foundAppointment = service.FindAppointments(WellKnownFolderName.Calendar, userCalendar); List<Appointment> filteredApt = new List<Appointment>(); foreach (Appointment termin in foundAppointment.Items) { if (termin.Subject == subjectInfomeeting || termin.Subject == subjectSommerfest) { //Distinguish Distribution Group string distributiongroup = "Distributiongrou1@email"; //Return the expanded group and create appointments for each member ExpandGroupResults distGroupMembers = service.ExpandGroup(distributiongroup); foreach (EmailAddress address in distGroupMembers.Members) { //Impersonate each distribution group member service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, address.Address); //Search and find the appointment CalendarView distGroupuserCalendar = new CalendarView(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(7)); FindItemsResults<Appointment> findDistGroupAppointments = service.FindAppointments(WellKnownFolderName.Calendar, distGroupuserCalendar); foreach (Appointment apt in findDistGroupAppointments.Items) { if (apt.Subject == termin.Subject) { //Say it exists Console.WriteLine(address + " " + termin.Subject + " " + termin.Start + " exists!"); //Delete the existing Appointment apt.Delete(DeleteMode.HardDelete); Console.WriteLine(address + " " + termin.Subject + " deleted!"); //Create Appointment Appointment appointment = new Appointment(service); appointment.Subject = termin.Subject; appointment.Location = termin.Location; appointment.Start = termin.Start; appointment.End = termin.End; appointment.IsReminderSet = false; appointment.Save(SendInvitationsMode.SendToNone); Console.WriteLine(address + " " + termin.Subject + " created!"); } } } } } }
Untli now I am only able to delete and recreate the appointment only on the reference user... (I'm deleting the appointment first in order to avoid dupplicates).
Can you halp me on this one?
Thank you.
Regards
Ioannis