MikeSCOTT05 Posted September 26, 2005 Posted September 26, 2005 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.