Hi there,
I am trying to drag an attachment or attachments from outlook into my form.
I need it to then copy the attachment(s) to a specified location.
I have this working for dragging files from explorer, but I just can't figure out how to access the attachment to copy it.
The first method I tried which resulted in an error is as follows:
My second attempt was as follows:
Both resulting in errors.
Any help would be appreciated, thank you.
I am trying to drag an attachment or attachments from outlook into my form.
I need it to then copy the attachment(s) to a specified location.
I have this working for dragging files from explorer, but I just can't figure out how to access the attachment to copy it.
The first method I tried which resulted in an error is as follows:
vb Code:
Dim theStream As Stream = DirectCast(e.Data.GetData("FileGroupDescriptor"), Stream) Dim fileGroupDescriptor As Byte() = New Byte(511) {} theStream.Read(fileGroupDescriptor, 0, 512) Dim fileName2 As New System.Text.StringBuilder("") Dim i As Integer = 76 While fileGroupDescriptor(i) <> 0 fileName2.Append(Convert.ToChar(fileGroupDescriptor(i))) i += 1 End While theStream.Close() Dim theFile As String = "Z:\_TEST" + fileName2.ToString() Dim ms As MemoryStream = DirectCast(e.Data.GetData("FileContents", True), MemoryStream) Dim fileBytes As Byte() = New Byte(ms.Length - 1) {} ms.Position = 0 ms.Read(fileBytes, 0, CInt(ms.Length)) Dim fs As New FileStream(theFile, FileMode.Create) fs.Write(fileBytes, 0, CInt(fileBytes.Length)) fs.Close()
My second attempt was as follows:
vb Code:
Dim objOL As New Microsoft.Office.Interop.Outlook.Application Dim objMI As Microsoft.Office.Interop.Outlook.MailItem For Each objMI In objOL.ActiveExplorer.Selection() Dim strFile As String = IO.Path.Combine("Z:\_TEST", (objMI.Subject + ".msg").Replace(":", "")) Try objMI.SaveAs(strFile) Catch ex As Exception MsgBox(ex.ToString) End Try Next
Both resulting in errors.
Any help would be appreciated, thank you.






