Greetings all,
I'm having a problem programmatically calling SendAndReceive in my Outlook Addin. I'm using Visual Studio 2008 and Outlook 2007. I expect this is due to me not having a complete understanding of what is going on in my code, but I'm hoping someone will be willing to enlighten me.
Here's a simplified version of the code I'm trying to make work. Most of this was put in place using the VS>New Project>Outlook 2007 Add-in function.
This is pretty simplified, but my intention is to trigger a "F9" send receive all when opening an inspector. I've also trying replacing the code in try block with this:Code:public partial class ThisAddIn { private Outlook.Inspectors inspectors; private void ThisAddIn_Startup(object sender, System.EventArgs e) { inspectors = Application.Inspectors; inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(inspectors_NewInspector); } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { } private void inspectors_NewInspector(Outlook.Inspector inspector) { try { Globals.ThisAddIn.Application.Session.SendAndReceive(false); } catch (Exception exc) { MessageBox.Show("Item Write - Send/Receive failed.\n" + exc.Message.ToString(), "OK"); } } #region VSTO generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InternalStartup() { this.Startup += new System.EventHandler(ThisAddIn_Startup); this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); } #endregion }
with the same results.Code:Outlook.Application app = Application; Outlook.NameSpace nsp = app.GetNamespace("Mapi"); nsp.Logon("Mapi", null, true, false); nsp.SendAndReceive(true);
Speaking of results. In the debugger, when I hit eitherorCode:Globals.ThisAddIn.Application.Session.SendAndReceive(false);, the program throws an exception with the message: "The operation failed."Code:nsp.SendAndReceive(true);
Any thoughts on what I'm doing wrong would be much appreciated.
Thanks,
Steve


Reply With Quote



Bookmarks