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
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