none
Cannot filter Outlook AppointmentItem with start time RRS feed

  • Question

  • This is my try to find an Appointment in Outlook calendar:

      
     var calendar = outlookApplication.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
            
        if (calendar == null || calendar.Items == null)
        {
           return null;
        }
    
        DateTime appointmentStart = new DateTime(2013, 04, 02, 10, 0 ,0);
        
        string filter = string.Format("[Start] = '{0}'", appointmentStart );
        var calendarItems = calendar.Items.Restrict(filter);



    This way I cannot find the Appointmen in calendar, but I have one on 02 Apr. 2013 at 10:00:00.
    Wednesday, March 20, 2013 7:35 AM

Answers

  • this is the answer:

    string.Format("[Start] = '{0}'", appointmentStart.ToString("g"));

    • Marked as answer by MikroDel Wednesday, March 20, 2013 12:12 PM
    Wednesday, March 20, 2013 12:12 PM

All replies

  • this is the answer:

    string.Format("[Start] = '{0}'", appointmentStart.ToString("g"));

    • Marked as answer by MikroDel Wednesday, March 20, 2013 12:12 PM
    Wednesday, March 20, 2013 12:12 PM
  • Do not use "=" when searching on the date/time values. You will never get a match due to round-off errors. Use a range, e.g. (start > value - 1 minute) and  (start < value + 1 minute). Or, better yet, open the appointment by its entry id (Namespace.GetItemfromID) or search by another property (e.g. Subject).

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

    Wednesday, March 20, 2013 12:59 PM