Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27518

VS 2010 Drag and Drop - Outlook Attachment

$
0
0
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:
vb Code:
  1. Dim theStream As Stream = DirectCast(e.Data.GetData("FileGroupDescriptor"), Stream)
  2.             Dim fileGroupDescriptor As Byte() = New Byte(511) {}
  3.             theStream.Read(fileGroupDescriptor, 0, 512)
  4.  
  5.             Dim fileName2 As New System.Text.StringBuilder("")
  6.             Dim i As Integer = 76
  7.             While fileGroupDescriptor(i) <> 0
  8.                 fileName2.Append(Convert.ToChar(fileGroupDescriptor(i)))
  9.                 i += 1
  10.             End While
  11.             theStream.Close()
  12.  
  13.             Dim theFile As String = "Z:\_TEST" + fileName2.ToString()
  14.  
  15.             Dim ms As MemoryStream = DirectCast(e.Data.GetData("FileContents", True), MemoryStream)
  16.             Dim fileBytes As Byte() = New Byte(ms.Length - 1) {}
  17.             ms.Position = 0
  18.             ms.Read(fileBytes, 0, CInt(ms.Length))
  19.  
  20.             Dim fs As New FileStream(theFile, FileMode.Create)
  21.             fs.Write(fileBytes, 0, CInt(fileBytes.Length))
  22.  
  23.             fs.Close()


My second attempt was as follows:
vb Code:
  1. Dim objOL As New Microsoft.Office.Interop.Outlook.Application
  2.  
  3.             Dim objMI As Microsoft.Office.Interop.Outlook.MailItem
  4.             For Each objMI In objOL.ActiveExplorer.Selection()
  5.                 Dim strFile As String = IO.Path.Combine("Z:\_TEST", (objMI.Subject + ".msg").Replace(":", ""))
  6.                 Try
  7.  
  8.                     objMI.SaveAs(strFile)
  9.                 Catch ex As Exception
  10.                     MsgBox(ex.ToString)
  11.                 End Try
  12.             Next

Both resulting in errors.

Any help would be appreciated, thank you.

Viewing all articles
Browse latest Browse all 27518

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>