Results 1 to 1 of 1

Thread: Reading Outlook .msg files with VB.Net 2010 created program, on Windows 7 with Outloo

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2011
    Posts
    38

    Reading Outlook .msg files with VB.Net 2010 created program, on Windows 7 with Outloo

    I am using the following code to get information from Outlook .msg files (created by Save As from
    Outlook), such as .SenderName, etc., as shown in the code. This works on XP with Outlook 2007
    on all but two of many .msg files.

    I posted a problem on the not handling of those two files. This is a different problem.

    I get an error when trying to access a .msg file when running on Windows 7 with Outlook 2010 installed.
    The program was created, and the .msi built, on XP/Outlook 2007. The .msg files were created with
    Outlook 2003 and 2007.

    I get the following error:
    System.InvalidCastException: Unable to cast COM object of type
    'Microsoft.Office.Interop.Outlook.ApplicationClass'
    to interface type 'Microsoft.Office.Interop.Outlook._Application'.
    This operation failed because the QueryInterface call on the COM component for the interface with
    IID '{00063001-0000-0000-C000-000000000046}' failed due to the following error:
    The RPC server is unavailable. (Exception from HRESULT: 0x800706BA).
    at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, Boolean& pfNeedsRelease)
    at Microsoft.Office.Interop.Outlook.ApplicationClass.CreateItem(OlItemType ItemType)
    at SearchDBs.frmMain.SearchAMSG(Int32 iThisDatabase)

    I don't have a line number, but I think the error is on the following line:
    oMail = CType(oOutL.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)

    Could this be because my program was created with a reference for Outlook 2007 instead of 2010?

    I am not finding much with Google on reading .msg files with Outlook 2010 installed.

    Any ideas of how to process the .msg files?

    Thanks.

    Code:
      Dim oOutL As New Outlook.Application
      Dim oMail As Outlook.MailItem
      Dim email As Outlook.MailItem
    
          oMail = CType(oOutL.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)
    
          Dim MsgFileName As String
          MsgFileName = ChangeToSharedPath(gsDatabaseNames(iThisDatabase))
    
          email = oMail.Application.Session.OpenSharedItem(MsgFileName)
    
          With email
            AllOfMSGPreserveCase = .SenderName & .SentOn & .To & .CC & .BCC & .Subject & .Body
            AllOfMSGPreserveCase &= AttachmentsList
          End With
    Last edited by MLarsB; Aug 3rd, 2012 at 06:04 PM. Reason: Added line: Dim oOutL As New Outlook.Application

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width