I am working on VSTO Outlook AddIn Project using c# and trying to add DocumentItem in outlook using following method -
protected void CreateWordDocument(string strPhysicalFilePath, Outlook.Folder ParentFolder)
{
Outlook.DocumentItem objDocItem = null;
Outlook.Attachment objAtt = null;
try
{
objDocItem = ParentFolder.Items.Add("IPM.Document");
objAtt = objDocItem.Attachments.Add(strPhysicalFilePath, );
objDocItem.Subject = objAtt.FileName;
string strFileType = Path.GetExtension(strPhysicalFilePath, );
switch (strFileType)
{
case ".doc":
case ".docx":
objDocItem.MessageClass = "IPM.Document.Word.Document.8"; break;
case ".xls":
case ".xlsx":
objDocItem.MessageClass = "IPM.Document.Excel.Sheet.8"; break;
case ".pps":
case ".ppt":
case ".pptx":
objDocItem.MessageClass = "IPM.Document.PowerPoint.Show.8"; break;
case ".txt":
objDocItem.MessageClass = "IPM.document.txtfile"; break;
}
objDocItem.Save();
}
catch (Exception ex)
{
ErrorLog.WriteError("ClassName", "CreateWordDocument()", ex.Message);
}
finally
{
if (objDocItem != null) Marshal.ReleaseComObject(objDocItem);
if (objAtt != null) Marshal.ReleaseComObject(objAtt);
}
}
but getting following error at line " objDocItem = ParentFolder.Items.Add("IPM.Document"); "
Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT)) in outlook.Items.Add() in VSTO Outlook Addin.
Same code is working fine on my computer but giving this error on another computer.
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.
I have found solution for this - There was issue with Target platform 32 bit or 64 bit. The machine where i was getting exception there 64 bit Office was installed and my outlook add in setup was built in 32 bit platform. I have recompiled and built outlook add in setup with 64 bit target platform and installed on that machine. now it is working fine.
User contributions licensed under CC BY-SA 3.0