I have a problem with development of a Office 365 Outlook Addin (Desktop). I need to modify certain properties on a MailItem opened with a custom form ( Form designed in Outlook, exported as OFS file and imported in to Visual Studio AddIn project) but the call of method 'Save' on MailItem object doesn't working, "Saved" property remain to "false" and when i close the inspector, Outlook prompt to save current item. No exception or error message raised on 'Save' call. But if i try to call 'Save' to the same MailItem in the AddIn body, the message is saved. I tried to write a simple test "addin" and i obtained the same result, but i can't understand this behaviour.
NB: with previous version of Outlook i haven't this issue. Any idea? Thanks so much!
Currently using VS2017, C#, .NET Framework 4.5, Interop library version 15.0
// ADD-IN BODY
private Outlook.Inspectors inspectors;
public static MailItem CurrentMailItem;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
inspectors = this.Application.Inspectors;
inspectors.NewInspector += Inspectors_NewInspector;
}
private void Inspectors_NewInspector(Inspector Inspector)
{
if (Inspector.CurrentItem is MailItem)
{
MailItem item = (MailItem)Inspector.CurrentItem;
item.MessageClass = "IPM.Note.MyReader";
item.Save();
bool saved = item.Saved;
Marshal.ReleaseComObject(item);
item = null;
}
}
// CUSTOM FORM:
private void FormRegion2_FormRegionShowing(object sender, System.EventArgs e)
{
// from this.OutlookItem
MailItem item = this.OutlookItem as MailItem;
item.Save();
bool saved = item.Saved; // <== SAVED=FALSE!
// from global variable (static)
ThisAddin.CurrentMailItem.Save();
saved = ThisAddin.CurrentMailItem.Saved; // <=== SAVED=FALSE!!!!
}