Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undelete a contact in outlook

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;
//.....
like image 456
Alister Avatar asked Oct 14 '22 08:10

Alister


2 Answers

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).

like image 134
Josh Avatar answered Oct 19 '22 10:10

Josh


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

like image 28
user269730 Avatar answered Oct 19 '22 10:10

user269730