We use redemption tools to populate stub-mails with real content. After calling RDOMail.Import(...)
on the selected item, we close and reopen the preview (reading) pane in outlook using
m_Explorer.ShowPane(MSOutlook.OlPane.olPreview, false);
m_Explorer.ShowPane(MSOutlook.OlPane.olPreview, true);
This method works well in Outlook 2007.
But in Outlook 2010 programmatical refresh attempts (Close/Open Reading pane, Deselect/Select the updated item) do not work at all. Outlook 2010 still shows the old version.
Does anyone have a hint or a possible solution?
Many thanks in advance.
Finally, we solved it!
The solution is to
1) Remove the item to update context.RemoveItem(TargetData.EntryID);
(We are using some abstractions over RDOMessage, MailItem, RDOFolder and MAPIFolder. But I think, the principle behind is quiet clear.
2) Add the new item (WithComCleanup
is from VSTOContrib project)
using (var msg = RDOSession.Resource.GetMessageFromMsgFile(pathToMSG)
.WithComCleanup())
{
msg.Resource.Move(context.RDOFolder);
msg.Resource.Save();
}
3) Attach an ItemAdd handler to RDOFolder or MAPIFolder, note that the items collection has to be declared on class level!
Why ItemAdd? Because neither RDOMail.OnModified
nor RDOMail.OnMoved
provided a valid EntryID required for MailItem retrieval. We write custom UserAttributes on fetching, and read them in ItemAdd
...
//...
m_OwnItems = m_Folder.Items
m_OwnItems.ItemAdd += new MSOutlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
//...
void Items_ItemAdd(object Item)
{
//Outlook 2010: Version 14, only Outlook 2010 supports `ClearSelection` and `AddToSelection`
if (Item is MSOutlook.MailItem && ApplicationController.Instance.ApplicationVersion.Major >= 14)
{
var mail = Item as MSOutlook.MailItem;
//Check that the added item is the one you added with GetMessageFromMsgFile
//...
if (m_Explorer.IsItemSelectableInView(mail))
{
m_Explorer.ClearSelection();
m_Explorer.AddToSelection(mail);
}
}
}
4) It's done! This behavior of Outlook 2010 annoyed us for the whole development time...