Home All Groups Group Topic Archive Search About

Drag and Drop from Outlook to Vb.net RichTextBox

Author
24 Aug 2006 1:55 PM
SStory
I want to drag a message from Outlook to a richtextbox on a vb.net form.  I
don't get the message body.  I have searched all over the place and found
nothing.

Does anyone know how to do this?  I don't care about attachments. I just
need the text.

Thanks,

Shane

Author
24 Aug 2006 2:43 PM
Peter Proost
If you open the message you can just select and drag drop the body to the
richtextbox like this:

Private Sub RichTextBox1_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragEnter
        If (e.Data.GetDataPresent(DataFormats.StringFormat)) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub RichTextBox1_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop
        RichTextBox1.Text =
e.Data.GetData(DataFormats.StringFormat).ToString
    End Sub

I don't think it's possible to get the message by only dragging and dropping
the message header, I think you can only get From, Subject, Received, and
Size this way

Hope this helps

Greetz Peter



--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

Show quoteHide quote
"SStory" <nospam@nospam.com> schreef in bericht
news:uDpZDT4xGHA.2300@TK2MSFTNGP05.phx.gbl...

> I want to drag a message from Outlook to a richtextbox on a vb.net form.
I
> don't get the message body.  I have searched all over the place and found
> nothing.
>
> Does anyone know how to do this?  I don't care about attachments. I just
> need the text.
>
> Thanks,
>
> Shane
>
>
Author
24 Aug 2006 3:38 PM
SStory
That's a real bummer, because you can drag and drop to the desktop and get
everything it seems in an .msg file.


Show quoteHide quote
"Peter Proost" <pproost@nospam.hotmail.com> wrote in message
news:OWpMgt4xGHA.4960@TK2MSFTNGP05.phx.gbl...
> If you open the message you can just select and drag drop the body to the
> richtextbox like this:
>
> Private Sub RichTextBox1_DragEnter(ByVal sender As Object, ByVal e As
> System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragEnter
>        If (e.Data.GetDataPresent(DataFormats.StringFormat)) Then
>            e.Effect = DragDropEffects.Copy
>        Else
>            e.Effect = DragDropEffects.None
>        End If
>    End Sub
>
>    Private Sub RichTextBox1_DragDrop(ByVal sender As Object, ByVal e As
> System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop
>        RichTextBox1.Text =
> e.Data.GetData(DataFormats.StringFormat).ToString
>    End Sub
>
> I don't think it's possible to get the message by only dragging and
> dropping
> the message header, I think you can only get From, Subject, Received, and
> Size this way
>
> Hope this helps
>
> Greetz Peter
>
>
>
> --
> Programming today is a race between software engineers striving to build
> bigger and better idiot-proof programs, and the Universe trying to produce
> bigger and better idiots. So far, the Universe is winning. (Rich Cook)
>
> "SStory" <nospam@nospam.com> schreef in bericht
> news:uDpZDT4xGHA.2300@TK2MSFTNGP05.phx.gbl...
>
>> I want to drag a message from Outlook to a richtextbox on a vb.net form.
> I
>> don't get the message body.  I have searched all over the place and found
>> nothing.
>>
>> Does anyone know how to do this?  I don't care about attachments. I just
>> need the text.
>>
>> Thanks,
>>
>> Shane
>>
>>
>
>
Author
25 Aug 2006 7:40 AM
Peter Proost
After some researching I got a working sample using outlook automation, you
need a reference to the outlook object library for it to work. It check's to
see if the "Object Descriptor" contains outlook, the it opens an
outlookapplication class and get's the active explorer selected message,
from this the message body is retrieved.

Hope this helps


Private Sub RichTextBox1_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragEnter
        If e.Data.GetDataPresent("Object Descriptor") Then
            e.Effect = DragDropEffects.Copy
            '(0): "RenPrivateSourceFolder"
            '(1): "RenPrivateMessages"
            '(2): "FileGroupDescriptor"
            '(3): "FileContents"
            '(4): "Object Descriptor"
            '(5): "System.String"
            '(6): "UnicodeText"
            '(7): "Text"
        Else
            e.Effect = DragDropEffects.None
        End If

    End Sub

    Private Sub RichTextBox1_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop
        If (e.Data.GetDataPresent("Object Descriptor")) Then
            Dim myMem As New MemoryStream
            Dim myByte As Byte()
            Dim strCheck As String
            myMem = DirectCast(e.Data.GetData("Object Descriptor"),
MemoryStream)
            myByte = myMem.ToArray
            myMem.Close()
            For i As Integer = 0 To myByte.Length - 1
                If myByte(i) <> 0 Then
                    strCheck &= Convert.ToChar(myByte(i))
                End If
            Next

            If LCase(strCheck).IndexOf("outlook") > -1 Then
                Dim myOlApp As New Outlook.ApplicationClass
                Dim myExp As Outlook.Explorer = myOlApp.ActiveExplorer
                Dim myMailItem As Outlook.MailItem
                myMailItem = DirectCast(myExp.Selection.Item(1),
Outlook.MailItem)
                RichTextBox1.Text = myMailItem.Body
                myExp = Nothing
                myMailItem = Nothing
                myOlApp = Nothing
            End If

        End If
    End Sub

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

Show quoteHide quote
"SStory" <nospam@nospam.com> schreef in bericht
news:uO1xwM5xGHA.3608@TK2MSFTNGP06.phx.gbl...
> That's a real bummer, because you can drag and drop to the desktop and get
> everything it seems in an .msg file.
>
>
> "Peter Proost" <pproost@nospam.hotmail.com> wrote in message
> news:OWpMgt4xGHA.4960@TK2MSFTNGP05.phx.gbl...
> > If you open the message you can just select and drag drop the body to
the
> > richtextbox like this:
> >
> > Private Sub RichTextBox1_DragEnter(ByVal sender As Object, ByVal e As
> > System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragEnter
> >        If (e.Data.GetDataPresent(DataFormats.StringFormat)) Then
> >            e.Effect = DragDropEffects.Copy
> >        Else
> >            e.Effect = DragDropEffects.None
> >        End If
> >    End Sub
> >
> >    Private Sub RichTextBox1_DragDrop(ByVal sender As Object, ByVal e As
> > System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop
> >        RichTextBox1.Text =
> > e.Data.GetData(DataFormats.StringFormat).ToString
> >    End Sub
> >
> > I don't think it's possible to get the message by only dragging and
> > dropping
> > the message header, I think you can only get From, Subject, Received,
and
> > Size this way
> >
> > Hope this helps
> >
> > Greetz Peter
> >
> >
> >
> > --
> > Programming today is a race between software engineers striving to build
> > bigger and better idiot-proof programs, and the Universe trying to
produce
> > bigger and better idiots. So far, the Universe is winning. (Rich Cook)
> >
> > "SStory" <nospam@nospam.com> schreef in bericht
> > news:uDpZDT4xGHA.2300@TK2MSFTNGP05.phx.gbl...
> >
> >> I want to drag a message from Outlook to a richtextbox on a vb.net
form.
> > I
> >> don't get the message body.  I have searched all over the place and
found
> >> nothing.
> >>
> >> Does anyone know how to do this?  I don't care about attachments. I
just
> >> need the text.
> >>
> >> Thanks,
> >>
> >> Shane
> >>
> >>
> >
> >
>
>
Author
25 Aug 2006 7:10 PM
SStory
Peter,

Thanks for all of your help.  I'm glad there is a way to do it.  I am;
however, very sorry that it can't be done without automating Outlook.  It
would be nice to just grab from the clipboard.

-Shane

Show quoteHide quote
"Peter Proost" <pproost@nospam.hotmail.com> wrote in message
news:uxai%23lByGHA.1304@TK2MSFTNGP05.phx.gbl...
> After some researching I got a working sample using outlook automation,
> you
> need a reference to the outlook object library for it to work. It check's
> to
> see if the "Object Descriptor" contains outlook, the it opens an
> outlookapplication class and get's the active explorer selected message,
> from this the message body is retrieved.
>
> Hope this helps
>
>
> Private Sub RichTextBox1_DragEnter(ByVal sender As Object, ByVal e As
> System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragEnter
>        If e.Data.GetDataPresent("Object Descriptor") Then
>            e.Effect = DragDropEffects.Copy
>            '(0): "RenPrivateSourceFolder"
>            '(1): "RenPrivateMessages"
>            '(2): "FileGroupDescriptor"
>            '(3): "FileContents"
>            '(4): "Object Descriptor"
>            '(5): "System.String"
>            '(6): "UnicodeText"
>            '(7): "Text"
>        Else
>            e.Effect = DragDropEffects.None
>        End If
>
>    End Sub
>
>    Private Sub RichTextBox1_DragDrop(ByVal sender As Object, ByVal e As
> System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop
>        If (e.Data.GetDataPresent("Object Descriptor")) Then
>            Dim myMem As New MemoryStream
>            Dim myByte As Byte()
>            Dim strCheck As String
>            myMem = DirectCast(e.Data.GetData("Object Descriptor"),
> MemoryStream)
>            myByte = myMem.ToArray
>            myMem.Close()
>            For i As Integer = 0 To myByte.Length - 1
>                If myByte(i) <> 0 Then
>                    strCheck &= Convert.ToChar(myByte(i))
>                End If
>            Next
>
>            If LCase(strCheck).IndexOf("outlook") > -1 Then
>                Dim myOlApp As New Outlook.ApplicationClass
>                Dim myExp As Outlook.Explorer = myOlApp.ActiveExplorer
>                Dim myMailItem As Outlook.MailItem
>                myMailItem = DirectCast(myExp.Selection.Item(1),
> Outlook.MailItem)
>                RichTextBox1.Text = myMailItem.Body
>                myExp = Nothing
>                myMailItem = Nothing
>                myOlApp = Nothing
>            End If
>
>        End If
>    End Sub
>
> --
> Programming today is a race between software engineers striving to build
> bigger and better idiot-proof programs, and the Universe trying to produce
> bigger and better idiots. So far, the Universe is winning. (Rich Cook)
>
> "SStory" <nospam@nospam.com> schreef in bericht
> news:uO1xwM5xGHA.3608@TK2MSFTNGP06.phx.gbl...
>> That's a real bummer, because you can drag and drop to the desktop and
>> get
>> everything it seems in an .msg file.
>>
>>
>> "Peter Proost" <pproost@nospam.hotmail.com> wrote in message
>> news:OWpMgt4xGHA.4960@TK2MSFTNGP05.phx.gbl...
>> > If you open the message you can just select and drag drop the body to
> the
>> > richtextbox like this:
>> >
>> > Private Sub RichTextBox1_DragEnter(ByVal sender As Object, ByVal e As
>> > System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragEnter
>> >        If (e.Data.GetDataPresent(DataFormats.StringFormat)) Then
>> >            e.Effect = DragDropEffects.Copy
>> >        Else
>> >            e.Effect = DragDropEffects.None
>> >        End If
>> >    End Sub
>> >
>> >    Private Sub RichTextBox1_DragDrop(ByVal sender As Object, ByVal e As
>> > System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop
>> >        RichTextBox1.Text =
>> > e.Data.GetData(DataFormats.StringFormat).ToString
>> >    End Sub
>> >
>> > I don't think it's possible to get the message by only dragging and
>> > dropping
>> > the message header, I think you can only get From, Subject, Received,
> and
>> > Size this way
>> >
>> > Hope this helps
>> >
>> > Greetz Peter
>> >
>> >
>> >
>> > --
>> > Programming today is a race between software engineers striving to
>> > build
>> > bigger and better idiot-proof programs, and the Universe trying to
> produce
>> > bigger and better idiots. So far, the Universe is winning. (Rich Cook)
>> >
>> > "SStory" <nospam@nospam.com> schreef in bericht
>> > news:uDpZDT4xGHA.2300@TK2MSFTNGP05.phx.gbl...
>> >
>> >> I want to drag a message from Outlook to a richtextbox on a vb.net
> form.
>> > I
>> >> don't get the message body.  I have searched all over the place and
> found
>> >> nothing.
>> >>
>> >> Does anyone know how to do this?  I don't care about attachments. I
> just
>> >> need the text.
>> >>
>> >> Thanks,
>> >>
>> >> Shane
>> >>
>> >>
>> >
>> >
>>
>>
>
>