How to get save confirmation dialog result of outlook - c#

I don't know how to get result of save confirmation dialog of outlook (in C#).
This confirmation box is opened up by following:
Open mail in outlook
Made some changes in content
Close the mail
Please refer this image
I want to get this opened save confirm box and its result.
Thanks in advance.

Track the MailItem.Close / Write / AfterWrite events - Close will fire immediately before the prompt is shown, Write fires before the message is saved, AfterWrite immediately afterward.

There is no trivial way of getting such information. But you may track the sequence of events fired for the item and realize the answer following that way.
First, to handle item-level events you may develop a wrapper for an Outlook item like described in the Implement a wrapper for inspectors and track item-level events in each inspector article.
The MailItem.Close event is fired when the inspector associated with an item (which is an instance of the parent object) is being closed.
The MailItem.Write event is fired when an instance of the parent object is saved, either explicitly (for example, using the Save or SaveAs methods) or implicitly (for example, in response to a prompt when closing the item's inspector).
So, if you have got Close fired following by the Write event - that is your case!

Related

VSTO Outlook 2010 Cancel Inspector Close

I have seen other posts regarding Outlook 2007 stating that you can't cancel an inspector close event. Is this still true in Outlook 2010 or 2013? If it is possible, how do I do this?
Also, if I can't cancel the close, can I cancel the save?
I am not asking for any logic pertaining to a specific application. I just want to know if there is a line of code that I can pass a bool into or a property that I can set to false to cancel the close event/save event.
Edit: For some clarification, I want to cancel the contact page's close event.
MailItem.Close event passes the Cancel parameter which you can set to true.
To prevent an inspector from being closed, you can drop down to the Windows API level and override the Inspector's window proc. You can then intercept (and discard) WM_CLOSE and WM_SYSCOMMNAND Windows messages.

Outlook Add-In: event when email is moved through inspector

I need to change the category of a email when the inspector-window is closing - what I am doing with the Close event.
My problem is, if the user clicks "move to folder" in the inspector, the mail is moved, after this the close event is fired, but at this point I coannot change the mail any more, because it was changed trough the mail-move (eg: EntryID gets changed).
Any ideas?
An "before-Item-moved" event on the mail would be great - or a way to reload the changed mail.
Unfortunately there's no easy way to get folder that the email was moved to. Which means you'll have to use Redemption which has events for the RDOStore object that can detect changes to any folder. But you'd also have to monitor EVERY store, because the user can obviously move it anywhere. And because the EntryID has changed, you'd need to use PR_SEARCH_KEY as the unique identifier in order to even find the email and then apply the category to it. Not fun!
Another option may be to repurpose the Move To Ribbon button to intercept the move operation, but then you'd have to provide your own folder picker! Ugly!
There is a BeforeMove event available:
https://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.inspectorevents_10_event.beforemove%28v=office.14%29.aspx

Catch Outlook events when attaching/sending a file from another application

I'm trying to create an add-in for Outlook 2007/2010 to modify recipients of newly created email messages. Everything works fine if the user creates a new email message inside Outlook (I'm using the Inspectors.NewInspector event). But if the user uses another application (MS Word or Adobe Acrobat for example) to try to email an attachment, the NewInspector event isn't fired when the compose email window is displayed. Is there a straightforward approach to catching an event that is raised in a situation like this?
I've tried using the Application.ItemLoad event, but I can't access any methods or properties after I successfully cast it to an Outlook.MailItem (I get an error stating System.Runtime.InteropServices.COMException: The item’s properties and methods cannot be used inside this event procedure). I'm using C# in Visual Studio 2010.
If the Outlook.exe process is not running then the NewInspector won't fire since ThisAddIn_Startup is not called except when the user opens up Outlook directly.
Since Outlook is not already running when the external application opens the new Inspector window - you would have to manually call ThisAddIn_Startup yourself or attach any custom events that need to fire when the Inspector ribbon is loaded. The best place to do this is by handling CreateRibbonExtensibilityObject or RequestService methods.
protected override object RequestService(Guid serviceGuid)
{
if (serviceGuid == typeof(Office.IRibbonExtensibility).GUID)
this.ThisAddIn_Startup(this, null);
return base.RequestService(serviceGuid);
}
The only caveat with this is that you need to support method re-entry with ThisAddIn_Startup since the Ribbon and Outlook can both call the startup routine now. You will need to safely administer a lock to ensure you don't keep calling your Init (ThisAddIn_Startup) routine more than once.

C# VSTO Outlook 2007 / Sharepoint: AddIn wont save contact item

can somebody help: i have an AddIn which reads contacts from a Sharepoint Server.
The user can load a contact and make some changes or create a new one. At his point, saving the item works well. The Form closes and the item is beeing transfered to Sharepoint.
But if the user reopens the same contact again and trys to make a simple change, saving is no more possible: The element could not be saved because it was changed by another user or window. Would you like to place a copy in your standard folder" (this a my translation from german to english...) The user must restart Outlook to make his change! I dont know, why the "fxxx" this happens.
I hook into the "Write" event to check some rights and if all is ok i do a
Marshal.ReleaseComObject(item);
this.Dispose();
and call the Garbage Collector:
GC.WaitForPendingFinalizers();
GC.Collect();
Even i write these lines into the FormRegionClosed-Method the problem stays the same.
Yeehaaaa: found the problem!
in AddIn-Startup a have an event handler for setting the message class on the current item.
This item has to be Marshall'd too

event handler problems c#

I have a handle that fires when the ItemAdd event is triggered on the Sent Items folder in outlook. This handle prompts the user and depending on their selection then opens a custom windows form to save the sent email.
Now ... heres what happens ...
The prompt shows fine when an item is placed into the Sent Items folder, if you dismiss it it will show again fine the next time the event is triggered, and so on.
If you accept the prompt, the windows form shows and are able to save the email. But the next time an email is placed into the sent items folder the event doesnt fire, and hence the prompt doesnt even show!
if i put the same handle on Outlooks OnSend event instead of on the ItemAdd for the sent items folder all works just the same, except after the windows form is loaded the first time it will continue to be loaded (ie the event fires and is handled) perfectly the next time you want it to.
It appears showing the windows form for some reason causes either the event to stop firing or the handle to drop off the sent items folder (but only the sent items folder). The latter being more likely i think. I have an idea for a work around but im not really a fan of work arounds if i can get away with it.
Would anybody know what might be going on here?
Many thanks in advance to any thoughts people may have.
Cheers,
Stuv
I had a similar problem. It sounds like one of your variables is getting garbage collected. If you can post some code I might be able to help you.

Categories