drag and drop from Outlook 2k to vb.net form

MikeScott05

New member
Joined
Sep 26, 2005
Messages
2
Programming Experience
5-10
Hi There,

I was wondering if anyone knows how to handle drag/drop of an Outlook item to a vb.net form? What I want to do is save the dropped Outlook item as a .msg file. Please see code below:

note that objMemoryStream = e.Data.GetData("FileContents")
returns nothing - I had expected to read file data from this.

Any help much appreciated

Thanks

Mike


Private Sub frmMain_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragDrop
Dim aFiles() As String
Dim intCount As Integer
Dim strFile As String
Dim objMemoryStream As MemoryStream
Dim aFileGroupArray(512) As Byte
Dim objFileStream As FileStream
Dim strFileName As String

If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
'handle files fropped from explorer
aFiles = e.Data.GetData(DataFormats.FileDrop)
For intCount = 0 To aFiles.Length - 1
strFile = aFiles(intCount).ToString
AddFile(strFile)
SavePending(strFile)
Next

ElseIf (e.Data.GetDataPresent("FileGroupDescriptor")) Then
'handle items from Outlook
objMemoryStream = e.Data.GetData("FileGroupDescriptor", True)
objMemoryStream.Read(aFileGroupArray, 0, 512)
Dim fileName As StringBuilder = New StringBuilder(256)

'following code extracts file name of message
For intCount = 76 To 512
fileName.Append(Convert.ToChar(aFileGroupArray(intCount)))
Next

objMemoryStream.Close()
strFileName = Path.GetTempPath & fileName.ToString

'following line of code returns nothing
'so can't read file contents into memory stream
objMemoryStream = e.Data.GetData("FileContents")

Dim aFileBytes(objMemoryStream.Length) As Byte

objMemoryStream.Position = 0
objMemoryStream.Read(aFileBytes, 0, (objMemoryStream.Length))

'create .msg file
objFileStream = New FileStream(strFileName, FileMode.Create)
objFileStream.Write(aFileBytes, 0, (aFileBytes.Length))
End If
End Sub
 
i posted this question a couple years ago on here
i'd found a c# example that would allow the user to drag&drop email attachments onto a vb.net form and it would copy it to a temp directory of which i wanted it to allow a user to drop a file from windows onto a form but the idea is the same and the example that was converted to vb.net allows for both outlook and windows file drops

http://www.vbdotnetforums.com/showpost.php?p=2785&postcount=5

just download the zip file and perhaps this will help
 
Thanks for the reply:

I tried the vb.net code in the zip attachment but the memorystream object, ms, returns nothing despite the GetDataPresent returning true (see code snippet below)

I tried it with Outlook 2000/2003 mail with attachment but got same result. Did you actually get the code working with Outlook and if so what version?

Any ideas much appreciated.


If e.Data.GetDataPresent("FileContents", True) Then
Dim ms As MemoryStream =
CType(e.Data.GetData("FileContents", True), IO.MemoryStream)
 
Back
Top