Is Restrict Dynamic

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I'm using the Items::Restrict method in my addin. I'm looping for all mails
that I haven't processed yet depending on a user property and after
processing the mail I change this property. I found that changing property
when I loop for the restricted items affect the restricted items list.
My code is similar to:
{
_ItemsPtr pItems = NULL;
HRESULT hr = pFolder->get_Items( & pItems );
_ItemsPtr pRestrictedItems = pItems->Restrict( "NOT( [Processed] = 1" );
_MailItemPtr pMail = pRestrictedItems->GetFirst( );
long l = pRestrictedItems->GetCount( );
for( long lIndex = 0; lIndex < lItemsCount; lIndex++ )
{
if( pMail )
{
//Procees Mail...
// Change the [Processed] user property to 1
// pMail->Save( );
}
}
}

When testing this code, I found that the for loop ends with lIndex = 218
where the lCount = 500.
 
Call Restrict, save all entry ids to a list first, then loop through your
list (rather that the restricted items collection) retrieving the items
using Namespace.GgetItemfromID.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Thanks a lot for your reply.
I found that the Items collection is a dynamic collection!!!!
You can find strange things here:
http://msdn2.microsoft.com/en-us/library/aa155748(office.10).aspx#olcollections_restrict


....
Dmitry Streblechenko said:
Call Restrict, save all entry ids to a list first, then loop through your
list (rather that the restricted items collection) retrieving the items
using Namespace.GgetItemfromID.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

MON205 said:
Hello,
I'm using the Items::Restrict method in my addin. I'm looping for all
mails
that I haven't processed yet depending on a user property and after
processing the mail I change this property. I found that changing property
when I loop for the restricted items affect the restricted items list.
My code is similar to:
{
_ItemsPtr pItems = NULL;
HRESULT hr = pFolder->get_Items( & pItems );
_ItemsPtr pRestrictedItems = pItems->Restrict( "NOT( [Processed] = 1" );
_MailItemPtr pMail = pRestrictedItems->GetFirst( );
long l = pRestrictedItems->GetCount( );
for( long lIndex = 0; lIndex < lItemsCount; lIndex++ )
{
if( pMail )
{
//Procees Mail...
// Change the [Processed] user property to 1
// pMail->Save( );
}
}
}

When testing this code, I found that the for loop ends with lIndex = 218
where the lCount = 500.
 
Back
Top