none
Outlook Interop - Check if item still exist by EntryID RRS feed

  • Question

  • Hi,

    Is there a way to check if item still exist by the EntryID?

    i know i can try get it from namespace GetItemFromID and catch ComExceptiion if it's not exist, but i am not sure this is the best way.

    I don't want to retrieve the item as well just check if it still in the Store.

    Thanks.


    • Edited by sharon8811 Friday, June 30, 2017 9:44 PM misspelled
    Friday, June 30, 2017 9:33 PM

All replies

  • Hello,

    The NameSpace.GetItemFromID method is a reasonable way to go because search methods from the OOM don't support binary properties (like EntryID).

    The EntryID changes when an item is moved into another store, for example, from your Inbox to a Microsoft Exchange Server public folder, or from one Personal Folders (.pst) file to another .pst file. Solutions should not depend on the EntryID property to be unique unless items will not be moved.

    I'd suggest using a low-level property instead - PR_SEARCH_KEY . MAPI uses specific rules for constructing search keys for message recipients. The search key is formed by concatenating the address type (in uppercase characters), the colon character ':', the e-mail address in canonical form, and the terminating null character. Canonical form here means that case-sensitive addresses appear in the correct case, and addresses that are not case-sensitive are converted to uppercase. This is important in preserving correlations among messages.

    A MAPI message object will have a unique value assigned on creation for PR_SEARCH_KEY, and if the object is copied this property value is copied as well. 


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Saturday, July 1, 2017 3:15 PM
  • Hello Eugene,

    Thank you for the answer,

    I am using tracking the pr_search_key as well, but the problem is that it is not unique, for example when copying the item in several folders it will have the same key and in case it is a sent item and the user sent himself a copy the sent email and the received email will have the same key.

    If NameSpace.GetItemFromID is the most reasonable way to go i will use it.

    Saturday, July 1, 2017 4:46 PM
  • Hello,

    In my options, MailItem.EntryID is the property to represent unique Entry ID of mailitem. If you want to find the unique mailItem, it seems to be the only property.

    If you do not want to retrieve the item in Store, the only option is GetItemFromID, and as you have found, you need to catch Exception due to that when passing an invalid or not exist EntryID, you will get exception.

    I agree with you to use GetItemFromID.

    For one note, you need to pay attention to such a scenario, if you move the mail item from one Folder to another Folder, the EntryID will change, and for this scenario, the mail Item is different. You will not get the mail item by previous EntryID when moving mailItem.

    You could refer the link below for more information.

    #MailItem.EntryID Property (Outlook)

    https://msdn.microsoft.com/VBA/Outlook-VBA/articles/mailitem-entryid-property-outlook

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, July 3, 2017 8:44 AM
    Moderator