I have the following code and the code is having a problem in the line (taskItem.Send();)
----------------------------------error message----------------------------------------------------------------
System.Runtime.InteropServices.COMException was unhandled by user code
Message="Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))"
Source=""
ErrorCode=-2147467260
StackTrace:
at Microsoft.Office.Interop.Outlook._TaskItem.Send()
at Incident_Coordinators.FormCode.CTRL103_7_Clicked(Object sender, ClickedEventArgs e) in C:\Documents and Settings\pluttod.ONE\My Documents\InfoPath Projects\Incident Coordinators-3\FormCode.cs:line 76
at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
-------------------------------------------code-----------------------------------------------------------------------
using
Microsoft.Office.InfoPath;
using
System;
using
System.Windows.Forms;
using
System.Xml;
using
System.Xml.XPath;
using
Outlook = Microsoft.Office.Interop.Outlook;
using
System.Reflection;
using
mshtml;namespace Incident_Coordinators
{
public partial class FormCode
{
// Member variables are not supported in browser-enabled forms.
// Instead, write and read these values from the FormState
// dictionary using code such as the following:
//
// private object _memberVariable
// {
// get
// {
// return FormState["_memberVariable"];
// }
// set
// {
// FormState["_memberVariable"] = value;
// }
// }
// NOTE: The following procedure is required by Microsoft Office InfoPath.
// It can be modified using Microsoft Office InfoPath.public void InternalStartup()
{
//((ButtonEvent)EventManager.ControlEvents["CTRL76_7"]).Clicked += new ClickedEventHandler(CTRL76_7_Clicked);((ButtonEvent)EventManager.ControlEvents["CTRL103_7"]).Clicked += new ClickedEventHandler(CTRL103_7_Clicked);
//((ButtonEvent)EventManager.ControlEvents["CTRL134"]).Clicked += new ClickedEventHandler(CTRL134_Clicked);
}
public void CTRL103_7_Clicked(object sender, ClickedEventArgs e)
{
// Get a reference to the Main datasourceXPathNavigator root = MainDataSource.CreateNavigator();
// Create an Outlook applicationOutlook.Application outlookApp = new Outlook.Application();
// Get NameSpace and LogonOutlook.NameSpace outlookNS = outlookApp.GetNamespace("mapi");
outlookNS.Logon(
"/dfs:myFields/@User", Missing.Value, false, true);
// Create a new TaskItemOutlook.TaskItem taskItem =
(Outlook.
TaskItem)outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olTaskItem);
// Set some common propertiesString Recipient = root.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:EHS_Incident_Investigation_Main/@LIEmail", NamespaceManager).Value;
taskItem.Subject = root.SelectSingleNode(
"/dfs:myFields/dfs:dataFields/d:EHS_Incident_Investigation_Main/@Notification_ID", NamespaceManager).Value;taskItem.Body = "You have been selected to lead the noted investigation. This investigation is required to be completed by the noted date. Please confirm the accepts of this task";
// root.SelectSingleNode("test", NamespaceManager).Value;string StartDateTime =
//String.Format("{0}T{1}",root.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:EHS_Incident_Investigation_Main/@RequiredDate-1", NamespaceManager).Value;
string ReminderDate =
//String.Format("{0}T{1}",root.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:EHS_Incident_Investigation_Main/@Reminder_Date-1", NamespaceManager).Value;
taskItem.StartDate =
Convert.ToDateTime(StartDateTime);taskItem.ReminderSet = true;taskItem.ReminderTime = Convert.ToDateTime(ReminderDate);
taskItem.Assign();
taskItem.Recipients.Add(Recipient);
taskItem.Recipients.ResolveAll();
taskItem.Send();
// Save to Tasks
//taskItem.Save();
// Logoff
outlookNS.Logoff();
// Clean uptaskItem = null;
outlookNS =
null;outlookApp = null;
}
}
}