开发者

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.A开发者_JAVA百科sString;
//.....


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜