Solved

Drag Drop email from Outlook

Posted on 2010-08-26
9
1,170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 33530111
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
ID: 33530256
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 70

Expert Comment

by:Éric Moreau
ID: 33530270
I will check tonight on another PC that has Outlook 2010 installed
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 33536443
can you try my demo application? I just tried it at home with Outlook 2010 and it is working.
0
 

Author Comment

by:previewservices
ID: 33564941
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 70

Expert Comment

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

Author Comment

by:previewservices
ID: 33565786
How do you mean? I'm not too familiar with this. Thanks for your help.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 33566144
0
 

Author Comment

by:previewservices
ID: 33585156
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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