drag-drop from outlook to a WinForm

  • Thread starter Thread starter Thomas
  • Start date Start date
T

Thomas

Hi all,
I've got a half-functioning drag-drop from outlook app running.
I can get the name of the message from the FileGroupDescriptor part, but
whenever I try to get the FileContents part, I allways get Nothing back.
I've posted my code below - I hope someone here has a solution to this.

Cheers
Thomas

Private Sub Label1_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles Label1.DragDrop

Dim header As IO.MemoryStream

Dim data As IO.MemoryStream

Dim fs As IO.FileStream

Dim filePath As String = ""

Dim fileName As String = ""

' check the formats supported

Dim s() As String

Dim sFormat As String

s = e.Data.GetFormats

For Each sFormat In s

Me.ListBox1.Items.Add("Supported format: " & sFormat)

Next

' get the file group descriptor, for the file name

header = CType(e.Data.GetData("FileGroupDescriptor", False),
IO.MemoryStream)

header.Position = 76

Do While True

Dim l As Integer = header.ReadByte()

If (l = 0) Then Exit Do

fileName &= Convert.ToChar(l).ToString()

Loop

If fileName.Length = 0 Then Return

Me.ListBox1.Items.Add("Object dropped: " & fileName)

' get the actual dropped object

data = CType(e.Data.GetData("FileContents", False), IO.MemoryStream)

If Not data Is Nothing Then

Try

' get the data as a byte array

Dim b(data.Length) As Byte

data.Position = 0

data.Read(b, 0, data.Length)

' save the byte array to file

filePath = "D:\" + fileName

fs = New IO.FileStream(filePath, IO.FileMode.Create)

fs.Write(b, 0, data.Length)

Catch ex As Exception

Me.ListBox1.Items.Add("Exception: " & ex.Message)

Finally

fs.Close()

End Try

Else

Me.ListBox1.Items.Add("No data recieved")

End If

End Sub
 
Hi Thomas,
I can reproduce your problem, and am doing some research on it. I'll
update you as soon as I get some result. Thanks!

Kind regards,

Ying-Shen Yu [MS]
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
--------------------
| From: "Thomas" <[email protected]>
| Subject: drag-drop from outlook to a WinForm
| Date: Wed, 3 Sep 2003 17:55:59 +0200
| Lines: 102
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| NNTP-Posting-Host: cpe.atm2-0-1021215.0x503f4156.bynxx14.customer.tele.dk
80.63.65.86
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:51568
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Hi all,
| I've got a half-functioning drag-drop from outlook app running.
| I can get the name of the message from the FileGroupDescriptor part, but
| whenever I try to get the FileContents part, I allways get Nothing back.
| I've posted my code below - I hope someone here has a solution to this.
|
| Cheers
| Thomas
|
| Private Sub Label1_DragDrop(ByVal sender As Object, ByVal e As
| System.Windows.Forms.DragEventArgs) Handles Label1.DragDrop
|
| Dim header As IO.MemoryStream
|
| Dim data As IO.MemoryStream
|
| Dim fs As IO.FileStream
|
| Dim filePath As String = ""
|
| Dim fileName As String = ""
|
| ' check the formats supported
|
| Dim s() As String
|
| Dim sFormat As String
|
| s = e.Data.GetFormats
|
| For Each sFormat In s
|
| Me.ListBox1.Items.Add("Supported format: " & sFormat)
|
| Next
|
| ' get the file group descriptor, for the file name
|
| header = CType(e.Data.GetData("FileGroupDescriptor", False),
| IO.MemoryStream)
|
| header.Position = 76
|
| Do While True
|
| Dim l As Integer = header.ReadByte()
|
| If (l = 0) Then Exit Do
|
| fileName &= Convert.ToChar(l).ToString()
|
| Loop
|
| If fileName.Length = 0 Then Return
|
| Me.ListBox1.Items.Add("Object dropped: " & fileName)
|
| ' get the actual dropped object
|
| data = CType(e.Data.GetData("FileContents", False), IO.MemoryStream)
|
| If Not data Is Nothing Then
|
| Try
|
| ' get the data as a byte array
|
| Dim b(data.Length) As Byte
|
| data.Position = 0
|
| data.Read(b, 0, data.Length)
|
| ' save the byte array to file
|
| filePath = "D:\" + fileName
|
| fs = New IO.FileStream(filePath, IO.FileMode.Create)
|
| fs.Write(b, 0, data.Length)
|
| Catch ex As Exception
|
| Me.ListBox1.Items.Add("Exception: " & ex.Message)
|
| Finally
|
| fs.Close()
|
| End Try
|
| Else
|
| Me.ListBox1.Items.Add("No data recieved")
|
| End If
|
| End Sub
|
|
|
|
|
 
Hi Thomas,
How about your problems now, I've researched on this issue and also
discussed with others. However,
it seems like a limitation of the .NET Framekwork. For work arounds you may
refer to another similiar post threads, which may help you solve your
problem, thanks!

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=FSnhXeFc
DHA.460%40cpmsftngxa06.phx.gbl&rnum=2&prev=/groups%3Fq%3D%2522Ying-Shen%2BYu
%2522%2Bdrag/drop%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3DFSnhX
eFcDHA.460%2540cpmsftngxa06

Kind regards,

Ying-Shen Yu [MS]
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
--------------------
| X-Tomcat-ID: 219403138
| References: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: (e-mail address removed) (Ying-Shen Yu[MS])
| Organization: Microsoft
| Date: Thu, 04 Sep 2003 08:36:21 GMT
| Subject: RE: drag-drop from outlook to a WinForm
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
| Message-ID: <x5avj#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Lines: 86
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:51609
| NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
|
| Hi Thomas,
| I can reproduce your problem, and am doing some research on it. I'll
| update you as soon as I get some result. Thanks!
|
| Kind regards,
|
| Ying-Shen Yu [MS]
| Microsoft Support Engineer
|
| This posting is provided "AS IS" with no warranties, and confers no
rights.
| You assume all risk for your use. 2001 Microsoft Corporation. All rights
| reserved.
| --------------------
| | From: "Thomas" <[email protected]>
| | Subject: drag-drop from outlook to a WinForm
| | Date: Wed, 3 Sep 2003 17:55:59 +0200
| | Lines: 102
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| | Message-ID: <[email protected]>
| | Newsgroups: microsoft.public.dotnet.framework.windowsforms
| | NNTP-Posting-Host:
cpe.atm2-0-1021215.0x503f4156.bynxx14.customer.tele.dk
| 80.63.65.86
| | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.framework.windowsforms:51568
| | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
| |
| | Hi all,
| | I've got a half-functioning drag-drop from outlook app running.
| | I can get the name of the message from the FileGroupDescriptor part, but
| | whenever I try to get the FileContents part, I allways get Nothing back.
| | I've posted my code below - I hope someone here has a solution to this.
| |
| | Cheers
| | Thomas
| |
| | Private Sub Label1_DragDrop(ByVal sender As Object, ByVal e As
| | System.Windows.Forms.DragEventArgs) Handles Label1.DragDrop
| |
| | Dim header As IO.MemoryStream
| |
| | Dim data As IO.MemoryStream
| |
| | Dim fs As IO.FileStream
| |
| | Dim filePath As String = ""
| |
| | Dim fileName As String = ""
| |
| | ' check the formats supported
| |
| | Dim s() As String
| |
| | Dim sFormat As String
| |
| | s = e.Data.GetFormats
| |
| | For Each sFormat In s
| |
| | Me.ListBox1.Items.Add("Supported format: " & sFormat)
| |
| | Next
| |
| | ' get the file group descriptor, for the file name
| |
| | header = CType(e.Data.GetData("FileGroupDescriptor", False),
| | IO.MemoryStream)
| |
| | header.Position = 76
| |
| | Do While True
| |
| | Dim l As Integer = header.ReadByte()
| |
| | If (l = 0) Then Exit Do
| |
| | fileName &= Convert.ToChar(l).ToString()
| |
| | Loop
| |
| | If fileName.Length = 0 Then Return
| |
| | Me.ListBox1.Items.Add("Object dropped: " & fileName)
| |
| | ' get the actual dropped object
| |
| | data = CType(e.Data.GetData("FileContents", False), IO.MemoryStream)
| |
| | If Not data Is Nothing Then
| |
| | Try
| |
| | ' get the data as a byte array
| |
| | Dim b(data.Length) As Byte
| |
| | data.Position = 0
| |
| | data.Read(b, 0, data.Length)
| |
| | ' save the byte array to file
| |
| | filePath = "D:\" + fileName
| |
| | fs = New IO.FileStream(filePath, IO.FileMode.Create)
| |
| | fs.Write(b, 0, data.Length)
| |
| | Catch ex As Exception
| |
| | Me.ListBox1.Items.Add("Exception: " & ex.Message)
| |
| | Finally
| |
| | fs.Close()
| |
| | End Try
| |
| | Else
| |
| | Me.ListBox1.Items.Add("No data recieved")
| |
| | End If
| |
| | End Sub
| |
| |
| |
| |
| |
|
|
 
Back
Top