none
EWS API cannot PlayOnPhone for EmailMessage deleted with DeleteMode.MoveToDeletedItems RRS feed

  • Question

  • Hi,

    I have some code some that performs actions on emails in an inbox and then moves them to the Deleted Items folder. If the message was a UM message, I then want to playonphone for this message. However, after calling the Delete method, although the EmailMessage is still there and valid, it won't play.

    I just get "The specified object was not found in the store".

    I've tried re-binding via the original Id after the delete with no luck. I want to move the item to Delete Items first and play from there, so the code does not have to wait for the phone call to complete before it call "delete" the message.

    The code looks something like this:

    //Mark successful email as read and move to the Deleted Items folder
    em.IsRead = true;
    em.Update(ConflictResolutionMode.AlwaysOverwrite);
    ItemId itemId = em.Id;
    em.Delete(DeleteMode.MoveToDeletedItems);

    //Play on phone
    if (exs != null && sPlayOnPhoneNumber != "")
    {
        try
        {
            //Re-reference deleted item
            EmailMessage um = EmailMessage.Bind(exs, itemId, pSet);
            PhoneCall pc = exs.UnifiedMessaging.PlayOnPhone(um.Id, sPlayOnPhoneNumber);
            LogAction("    UM message played on phone number " + sPlayOnPhoneNumber, sLogfile);
        }
        catch (System.Exception e)
        {
            LogAction("    Failed to play UM message on phone number " + sPlayOnPhoneNumber + " - " + e.Message, sLogfile);
        }
    }

    Does anyone know how I can re-reference the still existing EmailMessage item after calling Delete(DeleteMode.MoveToDeletedItems) ?

    With Thanks,

    Rob

    P.S. PlayOnPhone works perfectly if I leave the item in the Inbox.

     




    • Edited by Rob.Ford Wednesday, September 14, 2011 8:57 PM
    Wednesday, September 14, 2011 8:44 PM

Answers

  • When you delete a message this way your not really deleteing it your moving it from one folder to the deleteditems folder. When you move an Item from one folder to another it gets another ItemId so the old Id at that stage is invalid so any attempt to load attachments etc or rebind will fail. I would suggest instead of using Delete you use Move and specify the DeleteItems folder as a target. The advantage of this method is that you will get returned the new ItemId eg

                    foreach (Item itItem in fiItems.Items) {
                        Item NewItem = itItem.Move(WellKnownFolderName.DeletedItems);
                    }
    

    Cheers
    Glen

     

    • Marked as answer by Rob.Ford Thursday, September 15, 2011 4:02 AM
    Thursday, September 15, 2011 3:40 AM

All replies

  • When you delete a message this way your not really deleteing it your moving it from one folder to the deleteditems folder. When you move an Item from one folder to another it gets another ItemId so the old Id at that stage is invalid so any attempt to load attachments etc or rebind will fail. I would suggest instead of using Delete you use Move and specify the DeleteItems folder as a target. The advantage of this method is that you will get returned the new ItemId eg

                    foreach (Item itItem in fiItems.Items) {
                        Item NewItem = itItem.Move(WellKnownFolderName.DeletedItems);
                    }
    

    Cheers
    Glen

     

    • Marked as answer by Rob.Ford Thursday, September 15, 2011 4:02 AM
    Thursday, September 15, 2011 3:40 AM
  • Thanks, Glen. I wasn't expecting the Id to change for a moved item I already had a reference to, your method works perfectly.

    Cheers,

    Rob

    Thursday, September 15, 2011 4:02 AM