Drag Drop Outlook MailItem onto ListView
Hi.
I am trying to dragdrop a outlook email item onto a listview, then save the item to disk as a .msg file but am unable to do so. I am using VS .NET 2003 Academic version, Windows XP.
The following is the code I am using. The filename is recieved, but I am unable to read the FileContents section (As it becomes nothing when I convert it to a stream). Also, the e.Data item will not cast to a Outlook.MailItem item. <Confusion, Anger, Sobbing, Wailing!!!> I don't care how I do this as long as the result is a .msg file on disk, containing the outlook mailitem. I can then pass the filepath to another function to complete my ultimate goal (hahaha!) !
Any help on this would be appreciated.![]()
Thanks,
Nick.
' item is a valid listview item. This is so that an evaluators
' details can be dragged from the evaluators list form onto
' the evaluation form.'See if the item being dragged is a listview item
e.Effect = DragDropEffects.CopyEndSubPrivateSub lvEventObjects_DragDrop(ByVal senderAsObject,ByVal eAs System.Windows.Forms.DragEventArgs)Handles lvEventObjects.DragDropIf e.Data.GetDataPresent("FileGroupDescriptor") =TrueThen'if the file is an email
Try CallMe.GetFileDescriptor(e)Dim iDOAsNew DataObject
iDO.SetData("System.IO.MemoryStream",True, e.Data.GetData("System.IO.MemoryStream",True)) Dim io_msAs Stream =CType(e.Data.GetData("FileContents",True), Stream) Dim fContentsAs Array = Array.CreateInstance(GetType(Byte), 512)
Call fContents.Clear(fContents, 0, 512)
io_ms.Read(fContents, 0, 512)
' Gets the data format(s) in the data object.Dim arrayOfFormatsAs [String]() = iDO.GetFormats() ' Stores the results in a string.
Dim theResultAsString = "The format(s) associated with the data are:" + _ ControlChars.Cr Dim iAsInteger For i = 0To arrayOfFormats.Length - 1
theResult += arrayOfFormats(i) + ControlChars.Cr
Next i ' Show the results in a message box.
MessageBox.Show(theResult)
Dim outlook_objAs Outlook.Application
outlook_obj = CreateObject("Outlook.Application") Dim outlook_mailitemAs Outlook.MailItem
' outlook_mailitem = CreateObject("Outlook.MailItem")
'outlook_mailitem = iDO.GetData("FileContents", True) Dim dofAs DataFormats.Format
Console.WriteLine(dof.Name)
' Console.WriteLine(DataFormats.Format) 'obj = iDO.GetData(DataFormats.GetFormat("FileContents", True) 'Now save it to the database Catch exAs ExceptionMsgBox("Exception: " & ex.Message)
EndTryEndIf'Update the list of event objects for the current item' Call PopulateEventObjectList()EndSubFriendStructure SizeL Friend WidthAsLong
Friend HeightAsLongEndStructureFriendStructure PointL Friend xAsLong
Friend yAsLongEndStructureFriendStructure FILESIZE Friend highAsDouble
Friend lowAsDoubleEndStructureFriendStructure FileDescriptor 'Describes a file.
Friend dwFlagsAsDouble
Friend CLSIDAs Guid
Friend SiZELAs SiZEL
Friend PointLAs PointL
Friend dwFileAttributesAsDouble
Friend ftCreationTimeAs System.Runtime.InteropServices.FILETIME
Friend ftLastAccessTimeAs System.Runtime.InteropServices.FILETIME
Friend ftLastWriteTimeAs System.Runtime.InteropServices.FILETIME
Friend nFileSizeHighAs FILESIZE
Friend FileNameAsStringEndStructureFriendFunction GetFileDescriptor(ByRef eAs System.Windows.Forms.DragEventArgs)As FileDescriptor'get the file group descriptor dataTry ' Dim theStream As System.IO.Stream = CType(e.Data.GetData("FileGroupDescriptor"), Stream) Call WriteFileFormats(e)
Dim idoAs DataObject = e.Data
Dim theblobAsByte() = ido.GetData(GetType(Byte))
Dim theStreamAs System.IO.Stream =CType(e.Data.GetData("FileContents"), Stream)
Console.WriteLine(theStream.Length()) ' Dim theStream As System.IO.Stream = CType(e.Data.GetData("Outlook.MailItem", True), Outlook.MailItem)
'Dim mi As Outlook.MailItem
' mi = CreateObject("Outlook.MailItem")
' mi = CType(e.Data.GetData("Outlook.MailItem"), Outlook.MailItem) ' Console.WriteLine(mi.SenderEmailAddress.ToString)
' mi.SaveAs("C:\mymail.msg")Dim fileGroupDescriptorAs Array = Array.CreateInstance(GetType(Byte), 512)
Call fileGroupDescriptor.Clear(fileGroupDescriptor, 0, 512)
theStream.Read(fileGroupDescriptor, 0, 512) 'write the output to a file
Call WriteByteArrayToFile_str(fileGroupDescriptor, 0, 512, "C:\mytest.txt")
Dim fdFileDescriptorAsNew FileDescriptor
theStream.Position = 0'Get the dwflags (Double)
theStream.Close()Catch exAs Exception
MsgBox(ex.Message)
EndTryEndFunction

