public static void Run()
        {
            // ExStart:CreateFoldersOnExchangeServerMailbox

            // Create instance of EWSClient class by giving credentials
            IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

            string             inbox          = client.MailboxInfo.InboxUri;
            string             folderName1    = "EMAILNET-35054";
            string             subFolderName0 = "2015";
            string             folderName2    = folderName1 + "/" + subFolderName0;
            string             folderName3    = folderName1 + " / 2015";
            ExchangeFolderInfo rootFolderInfo = null;
            ExchangeFolderInfo folderInfo     = null;

            try
            {
                client.UseSlashAsFolderSeparator = true;
                client.CreateFolder(client.MailboxInfo.InboxUri, folderName1);
                client.CreateFolder(client.MailboxInfo.InboxUri, folderName2);
            }
            finally
            {
                if (client.FolderExists(inbox, folderName1, out rootFolderInfo))
                {
                    if (client.FolderExists(inbox, folderName2, out folderInfo))
                    {
                        client.DeleteFolder(folderInfo.Uri, true);
                    }
                    client.DeleteFolder(rootFolderInfo.Uri, true);
                }
            }
            // ExEnd:CreateFoldersOnExchangeServerMailbox
        }
示例#2
0
        public static void Run()
        {
            using (IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "your.username", "your.Password"))
            {
                try
                {
                    // Create an appointmenta that will be added to secondary calendar folder

                    DateTime date      = DateTime.Now;
                    DateTime startTime = new DateTime(date.Year, date.Month, date.Day, date.Hour, 0, 0);
                    DateTime endTime   = startTime.AddHours(1);

                    string timeZone = "America/New_York";

                    Appointment[] listAppointments;
                    Appointment   appointment = new Appointment("Room 121", startTime, endTime, "*****@*****.**", "*****@*****.**");
                    appointment.SetTimeZone(timeZone);
                    appointment.Summary     = "EMAILNET-35198 - " + Guid.NewGuid().ToString();
                    appointment.Description = "EMAILNET-35198 Ability to add event to Secondary Calendar of Office 365";

                    // Verify that the new folder has been created
                    ExchangeFolderInfoCollection calendarSubFolders = client.ListSubFolders(client.MailboxInfo.CalendarUri);

                    string getfolderName;
                    string setFolderName = "New Calendar";
                    bool   alreadyExits  = false;

                    // Verify that the new folder has been created already exits or not

                    for (int i = 0; i < calendarSubFolders.Count; i++)
                    {
                        getfolderName = calendarSubFolders[i].DisplayName;

                        if (getfolderName.Equals(setFolderName))
                        {
                            alreadyExits = true;
                        }
                    }

                    if (alreadyExits)
                    {
                        Console.WriteLine("Folder Already Exists");
                    }
                    else
                    {
                        // Create new calendar folder
                        client.CreateFolder(client.MailboxInfo.CalendarUri, setFolderName, null, "IPF.Appointment");

                        Console.WriteLine(calendarSubFolders.Count);

                        // Get the created folder URI
                        string newCalendarFolderUri = calendarSubFolders[0].Uri;

                        // appointment api with calendar folder uri
                        // Create
                        client.CreateAppointment(appointment, newCalendarFolderUri);
                        appointment.Location = "Room 122";
                        // update
                        client.UpdateAppointment(appointment, newCalendarFolderUri);
                        // list
                        listAppointments = client.ListAppointments(newCalendarFolderUri);

                        // list default calendar folder
                        listAppointments = client.ListAppointments(client.MailboxInfo.CalendarUri);

                        // Cancel
                        client.CancelAppointment(appointment, newCalendarFolderUri);
                        listAppointments = client.ListAppointments(newCalendarFolderUri);

                        // appointment api with context current calendar folder uri
                        client.CurrentCalendarFolderUri = newCalendarFolderUri;
                        // Create
                        client.CreateAppointment(appointment);
                        appointment.Location = "Room 122";
                        // update
                        client.UpdateAppointment(appointment);
                        // list
                        listAppointments = client.ListAppointments();

                        // list default calendar folder
                        listAppointments = client.ListAppointments(client.MailboxInfo.CalendarUri);

                        // Cancel
                        client.CancelAppointment(appointment);
                        listAppointments = client.ListAppointments();
                    }
                }
                finally
                {
                }
            }
        }