Solved

Drag Drop email from Outlook

Posted on 2010-08-26
9
1,105 Views
Last Modified: 2012-05-10
Hello,

I have the below code which works find in Outlook 2007 where I can drag an email from Outlook into the textbox and the message appears in the textbox but it doesn't seem to work in Office 2010. How can I fix this?

The error i am getting says "Cannot create ActiveX component" which is being caught in the FindOutlookItem function.

Any ideas would be appreciated.
Thanks in advance.
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports Microsoft.Office.Interop.Outlook '( Add com reference Microsoft Outlook 10.0 Object Library)
Imports System.Collections
Imports Microsoft.Office.Interop

Public Class frmDDTest

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
        If e.Data.GetDataPresent("RenPrivateMessages") Then
            e.Effect = DragDropEffects.All
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub


    Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
        Dim dropString As String = e.Data.GetData(DataFormats.UnicodeText).ToString
        Dim mailData As Hashtable = ParseOutlookDropData(dropString)
        TextBox1.Text = FindOutlookItem(mailData).Body
    End Sub

    Private Function ParseOutlookDropData(ByVal data As String) As Hashtable
        Dim infoLines As String() = data.Split(Microsoft.VisualBasic.Chr(10))
        Dim headers As String() = infoLines(0).Split(Microsoft.VisualBasic.Chr(9))
        Dim record As String() = infoLines(1).Split(Microsoft.VisualBasic.Chr(9))
        Dim mailData As Hashtable = New Hashtable
        Dim i As Integer = 0
        While i < headers.Length
            mailData.Add(headers(i), record(i))
            System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1)
        End While
        Return mailData
    End Function

    Private Function FindOutlookItem(ByVal mailData As Hashtable) As Outlook.MailItem
        Dim outlook As Outlook.Application

        Try
            outlook = CType(Microsoft.VisualBasic.Interaction.GetObject("", "Outlook.Application"), Outlook.Application)


            Dim explorer As Outlook.Explorer = outlook.ActiveExplorer
            Dim mail As Outlook.MailItem = CType(explorer.Selection.Item(1), Outlook.MailItem)

            Dim x As Integer = 1
            ' If mail.Subject = mailData("Betreff").ToString Then
            Return mail
            ' Else
            ' Throw New ApplicationException("Error -Mail Requested not found?")
            ' End If

        Catch ex As System.Exception

            MsgBox(ex.Message)
        End Try

    End Function
End Class

Open in new window

0
Comment
Question by:previewservices
  • 5
  • 4
9 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
Comment Utility
you should go late-bound in not to be tied to any version of Outlook. check http://www.emoreau.com/Entries/Articles/2008/05/Dropping-a-Outlook-message-on-your-application.aspx
0
 

Author Comment

by:previewservices
Comment Utility
Thanks emoreau but still getting the same error when trying to go late-bound. It errors on line "Dim objOL As Object = GetObject(, "Outlook.Application")"
System.InvalidOperationException was unhandled
  Message=An error occurred creating the form. See Exception.InnerException for details.  The error is: Cannot create ActiveX component.
  Source=DragDrop Test
  StackTrace:
       at DragDrop_Test.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
       at DragDrop_Test.My.MyProject.MyForms.get_Form1()
       at DragDrop_Test.My.MyApplication.OnCreateMainForm() in C:\Users\Ross.PREVIEW\AppData\Local\Temporary Projects\DragDrop Test\My Project\Application.Designer.vb:line 35
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at DragDrop_Test.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
       Message=Cannot create ActiveX component.
       Source=Microsoft.VisualBasic
       StackTrace:
            at Microsoft.VisualBasic.Interaction.GetObject(String PathName, String Class)
            at DragDrop_Test.Form1..ctor() in C:\Users\Ross.PREVIEW\AppData\Local\Temporary Projects\DragDrop Test\Form1.vb:line 5
       InnerException:

Open in new window

0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
I will check tonight on another PC that has Outlook 2010 installed
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
can you try my demo application? I just tried it at home with Outlook 2010 and it is working.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:previewservices
Comment Utility
Strange, I still get an error. Would it matter i'm using VS2010? I get the below error in the label.
An error occured in the drop event
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: Interface not registered (Exception from HRESULT: 0x80040155).
   at Microsoft.Office.Interop.Outlook.ApplicationClass.ActiveExplorer()
   at WindowsApplication1.Form1.Label1_DragDrop(Object sender, DragEventArgs e) in C:\Users\Ross.PREVIEW\Desktop\Demo\Form1.vb:line 48

Open in new window

0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
I am using VS2010 too. Have you tried to cast as _Application?
0
 

Author Comment

by:previewservices
Comment Utility
How do you mean? I'm not too familiar with this. Thanks for your help.
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
0
 

Author Comment

by:previewservices
Comment Utility
I can't find the file msoutl.olb they talked about. I downloaded the demo of Office 2010 then entered the serial key. It seems to use a bootloader to run applications. For example the shortcut to Outlook is "C:\Program Files\Common Files\microsoft shared\Virtualization Handler\CVH.EXE" "Microsoft Outlook 2010 9014006204090000"
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now