I have an application written in Delphi that adds / updates contacts in outlook. The problem I'm having is that if the contact has been deleted in Outlook, the code still finds the contact and updates it - and the contact still remains deleted. Is there a way I can determine if the contact is deleted or undelete the contact?
Roughly the code looks something like:
OutlookApp := CreateOleObject('Outlook.Application');
Mapi := OutlookApp.GetNameSpace('MAPI');
//.....
try
if ContactOutlookEntryID.AsString <> '' then
aContact := Mapi.GetItemFromID(ContactOutlookEntryID.AsString);
except
end;
//try to locate the contact if they have been synchro'd before
if VarIsEmpty(aContact) then //if not found
aContact := Contacts.Items.Add(2); //add a new contact to outlook
aContact.LastName := ContactSurname.AsString;
//.....
When contacts are deleted they are put in the Deleted Items folder. There is no other "deleted" state other than being in that folder. "Undeleting" is as simple as moving it back out.
There is a Move method on the ContactItem object that you can use to move it back to the default contact folder which you can get with the NameSpace.GetDefaultFolder method.
EDIT To determine if the contact is in the deleted items folder you can look at the Parent property which should return a MAPIFolder object. You can then compare its EntryID against the one returned by GetDefaultFolder(olFolderDeletedItems).
Keep in mind that this is PST specific - the PST provider does not change the entry id when items are moved to different folders.
Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With