Mihai Caracostea
Mihai Caracostea

Reputation: 8466

Refresh Outlook mailitem

I have created an Outlook addin using NetOffice and it does exactly what it is meant to do: find inline images with broken src attributes (src="cid:somecontent@id") and try to fix them to point to the correct attachments. This is because from an external source, those attributes get messed up, and so do the cids of the attachments. But there is no problem here. The problem is that after the changes are saved to the MailItem, the inspector does not refresh it's view. The changes only get reflected after I restart Outlook, which is by no mean acceptable.

My question is: how can I force Outlook to refresh it's view of the current MailItem?

From what I could find from other Internet resources, Outlook caches that mailitem and because the CIDs are set using Extended Properties, it is not aware of the need to refresh.

Don't know exactly what code bits to post, since the code works fine for what it's intended. This is only a refreshing problem.

Upvotes: 0

Views: 2568

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49455

That is a known issue. Outlook doesn't propagate changes made through the object model until you re-open the item/inspector and release all references to the object (before re-opening).

Due to the fact that you need to close Outlook you don't release all the underlying COM objects instantly. Typically you need to close the inspector window and release all references (sometimes may be change the selected item in the explorer window).

Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. See Systematically Releasing Objects for more information.

Upvotes: 2

Related Questions