none
oItems.Restrict Filter RRS feed

  • Question

  • Hi,

    I have a question about restrict,

    Currently I am iterating all appointments and I want to narrow the search.

    I know there is a problem with restrict with some topics that I read.

    That you can’t release it after finish and I don’t know what is better and faster?

    Iterant on all appointments or using the restrict option

    My code is:

    Dim outlookNamespace As Outlook.NameSpace = Me.Application.GetNamespace("MAPI")
                Dim calendar As Outlook.MAPIFolder = outlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
                'release com object
                CalendarItem = calendar.Items
     	    Dim obj As Object
                For Each obj In CalendarItem
                    If TypeOf obj Is Outlook.AppointmentItem Then
                        If obj.Start >= Today Then
                          ThisAddIn.AppointmentList.AddAppointment(obj.Subject, obj.EntryID, obj.Start, obj.End)
                        End If
                    End If
                Next

     

    if i use restrict on CalendarItem  i can get only the appointments filtered

    what about releasing the appointment item i understood that looping with the for each loop

    is not recommended and you cant release the appointment how to do that correctly?

    One more Q when i use

    System.Runtime.InteropServices.Marshal.ReleaseComObject(obj) 

    i still can access it from other subs in my application i am just releasing the current reference yes?

     

    Tanks

    Patrick

    Tuesday, March 27, 2012 7:39 AM

Answers

  • i think dasl query can be used both in gettable as in restrict. As for recommending - measure yourself what is faster and use it, i never said that gettable is not recommended. As for code, ok from releasing com objects point of view, but i think you are missing last element in calendar items. Do not count to .Count -1 but rather to full .Count.

    • Marked as answer by Patrick12_3 Tuesday, March 27, 2012 12:13 PM
    Tuesday, March 27, 2012 12:08 PM

All replies

  • i think you can release items you get from 'restrict' function, i haven't heard about special case for that one. As for iterating simple 'for' loop is better and after you are done with each item in teration, call Marshal. ReleaseComObject. Also remember to call release on Items collection that you get from Restrict function. As for Restrict itself i remember hearing from Dimitry that you should not use it if you expect only very few items to return and from large overall amount of items as Restrict is cached on Exchange for 1 week by default and updated each time items are added/modified in folder. So you have to decide.
    Tuesday, March 27, 2012 8:09 AM
  • Hi Damian,

    so using the GetTable is beter? and then i will release it...?

    Patrick

    Tuesday, March 27, 2012 9:22 AM
  • yes, i would go with GetTable and proper filter if you expect to get only few (maybe 100) results and you need to do it once or twice at all, not once a day.
    Tuesday, March 27, 2012 9:55 AM
  • Hi,

    I expect to get around 10 and run it 5-6 times a day does it matter?


    I will Get only Items at current Day
    • Edited by Patrick12_3 Tuesday, March 27, 2012 10:34 AM
    Tuesday, March 27, 2012 10:30 AM
  • then maybe Restrict is not a bad idea. Measure both approaches and decide. Remember that you can use 'today' keyword in DASL based filters, like:

    @SQL = schema_name_of_date_property <= 'today'

    Tuesday, March 27, 2012 10:45 AM
  •  

    Hi,

    i understand that this line refers to GetTable i haven’t tried it yet

    @SQL = schema_name_of_date_property <= 'today'

    I don’t know what is the big diffrance betwean GetTable  and the Restrinct

    Can you please explain way using GetTable more then once a day is not recomanded and restrict is recomanded?

    Can you please look at this code and tell if it is the proper way of releasing the item?

    Tanks,

    Patrick

    Dim outlookNamespace As Outlook.NameSpace = Application.GetNamespace("MAPI")
    	    Dim calendar As Outlook.MAPIFolder = outlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
               
                CalendarItemEvent = calendar.Items
    	    System.Runtime.InteropServices.Marshal.ReleaseComObject(outlookNamespace)
    	    System.Runtime.InteropServices.Marshal.ReleaseComObject(calendar)
    	    outlookNamespace = Nothing
    	    calendar= Nothing
                     
         
                Dim i As Integer
                Dim obj As Outlook.AppointmentItem
                For i = 1 To CalendarItem.count - 1
                    obj = CalendarItem.Item(i)
                    If obj.Start >= Today  Then
                        ThisAddIn.AppointmentList.AddAppointment(obj.Location, obj.EntryID, obj.Start, obj.End)
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
                        obj = Nothing
                    End If
                Next
               
                System.Runtime.InteropServices.Marshal.ReleaseComObject(CalendarItem)
     	    CalendarItem = Nothing

    Tuesday, March 27, 2012 11:18 AM
  • i think dasl query can be used both in gettable as in restrict. As for recommending - measure yourself what is faster and use it, i never said that gettable is not recommended. As for code, ok from releasing com objects point of view, but i think you are missing last element in calendar items. Do not count to .Count -1 but rather to full .Count.

    • Marked as answer by Patrick12_3 Tuesday, March 27, 2012 12:13 PM
    Tuesday, March 27, 2012 12:08 PM
  • Tanks again Damian..

    Patrick

    Tuesday, March 27, 2012 12:11 PM
  • A DASL query can be used in a find or restriction. In general you won't want to use restrictions that will change as those will all be cached in Exchange for the default period. For a constant filter/restriction it doesn't matter if it's cached as it's not changing and won't lead to too many restrictions being cached.
     
    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "DamianD" <=?utf-8?B?RGFtaWFuRA==?=> wrote in message news:3bb145a9-e1f9-429c-95f5-c7aa4794558b...

    i think dasl query can be used both in gettable as in restrict. As for recommending - measure yourself what is faster and use it, i never said that gettable is not recommended. As for code, ok from releasing com objects point of view, but i think you are missing last element in calendar items. Do not count to .Count -1 but rather to full ..Count.


    Ken Slovak MVP - Outlook
    Tuesday, March 27, 2012 1:34 PM
    Moderator