none
How to catch reference to cyclical event from code [Outlook] RRS feed

  • Question

  • Hi, 

    Im writting a method to catch all events on a given day, i'm using AppointmentItem but it cant see cyclical event.

    I can find the cyclical event but only when they were created, Is there any way to find a reference on a given day to this cyclical event?

    Thanks for help ;)


    • Edited by xsaradeusek Friday, January 26, 2018 12:10 PM
    Friday, January 26, 2018 11:45 AM

Answers

  • Ok i found this information here https://msdn.microsoft.com/en-us/library/office/ff184586.aspx

    Anyway, Thanks for help a lot

    • Marked as answer by xsaradeusek Saturday, January 27, 2018 12:03 PM
    Saturday, January 27, 2018 12:03 PM

All replies

  • Do you mean a recurring appointment? Are you trying to retrieve all appointments in a given time frame, including instances of recurring appointments? You will need to use the Items.IncludeRecurrences property and restrict the items to a date/time range. See the example at https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/items-includerecurrences-property-outlook?f=255&MSPPError=-2147217396

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Friday, January 26, 2018 3:29 PM
  • Well, i'm looking for C# code

    i was trying this method, but still i cant see the cyclical event

    Maybe I will explain again. If I create a cyclical event repeating every day on monday, i want to see this event on tuesday, wednesday etc.

    Sorry if that wasnt clear xd

            public static IEnumerable<Outlook.AppointmentItem> GetCalendarItemsOnDate(this Outlook.MAPIFolder pCalendarFolder, DateTime pDateToRead)
            {
    
                var filter = "( [Start] >= '" + pDateToRead.ToString("MM/dd/yyyy") + "'" + " AND " + "  [End]  < '" + pDateToRead.AddDays(1).ToString("MM/dd/yyyy") + "' )";
                pCalendarFolder.Items.IncludeRecurrences = true;
                var outlookCalendarItems = pCalendarFolder.Items.Restrict(filter);
                outlookCalendarItems.IncludeRecurrences = true;
    
                foreach (Outlook.AppointmentItem item in outlookCalendarItems)
                {
                    yield return item;
                }
            }




    • Edited by xsaradeusek Friday, January 26, 2018 7:17 PM
    Friday, January 26, 2018 6:40 PM
  • You are setting IncludeRecurrences on one object and calling Restrict on another - you need to have a dedicated variable to store the Items collection to make sure you are dealing with the same object.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, January 26, 2018 7:32 PM
  • Thanks for help i will try do it tomorrow

    If i find a serious problem which I can't deal with, I will write

    Friday, January 26, 2018 7:55 PM
  • I wrote this very provisional code but still ...

    private static void TakeCalendarEvents()
            {
                Outlook.Application _app = new Outlook.Application();
                Outlook.MAPIFolder objFolder;
                Outlook.Explorer objExplorer;
                Outlook.MAPIFolder objSubFolder;
                Outlook.AppointmentItem objCalenderItem;
                Outlook.Folders objOutlookFolders;
    
                objOutlookFolders = _app.Session.Folders;
    
                for (int intFolderCtr = 1; intFolderCtr <= objOutlookFolders.Count; intFolderCtr++)
                {
                    objFolder = objOutlookFolders[intFolderCtr];
                    objFolder.Items.IncludeRecurrences = true;
                    objExplorer = objFolder.GetExplorer();
    
                    for (int intSubFolderCtr = 1; intSubFolderCtr <= objExplorer.CurrentFolder.Folders.Count; intSubFolderCtr++)
                    {
                        objSubFolder = objExplorer.CurrentFolder.Folders[intSubFolderCtr];
                        objSubFolder.Items.IncludeRecurrences = true;
    
                        try
                        {
                            for (int intAppointmentCtr = 1; intAppointmentCtr <= objSubFolder.Items.Count; intAppointmentCtr++)
                            {
                                objCalenderItem = objSubFolder.Items[intAppointmentCtr];
                                if (objCalenderItem.Start >= DateTime.Parse("27.01.2018"))
                                {
                                    Console.WriteLine(objCalenderItem.Subject);
                                }
                            }
                        }
                        catch (Exception) { }                                     
                    }
                }
                Console.ReadLine();
            }



    • Edited by xsaradeusek Saturday, January 27, 2018 11:32 AM
    Saturday, January 27, 2018 11:31 AM
  • Ok i found this information here https://msdn.microsoft.com/en-us/library/office/ff184586.aspx

    Anyway, Thanks for help a lot

    • Marked as answer by xsaradeusek Saturday, January 27, 2018 12:03 PM
    Saturday, January 27, 2018 12:03 PM